Padding in UITextField - xamarin.ios

Is it possible to set padding inside a UITextField, if so how?

I was also wondering, here you are:
UIView paddingView = new UIView(new CGRect(0, 0, 5, 20));
YourTextField.LeftView = paddingView;
YourTextField.LeftViewMode = UITextFieldViewMode.Always;
You can modify padding size of course by changing values above.
Hope this will help.

Related

How to measure ImageView before creating bitmap into it?

My ImageView is matching screen size on x-axis and is using remaining space on y-axis in my layout. I want to create bitmap into this ImageView with exactly the same size as the ImageView is. How to make it please? Can it be done by some automatic setting, should I call some measure function?
I tried SetAdjustViewBounds() but it didn't work for me.
Creating Bitmap big enough (I don't like much such a memory wasting) and setting SetScaleType(ImageView.ScaleType.Matrix) works, but still when I'm making drawing operations on canvas, I don't know real size of area I should paint into, both canvas and bitmap height are equal to yScreen while imgWeekView height is pretending to be 0, even though it paints whole desired area with gray color.
imgWeekView = new ImageView(context);
//imgWeekView.SetAdjustViewBounds(true);
imgWeekView.SetScaleType(ImageView.ScaleType.Matrix);
layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent,1f);
layoutParams.Height = 0;
imgWeekView.LayoutParameters = layoutParams;
Bitmap bitmap = Bitmap.CreateBitmap((int)xScreen, (int)yScreen, Bitmap.Config.Argb8888);
cnvWeekView = new Canvas(bitmap);
imgWeekView.SetImageBitmap(bitmap);
linearLayout.AddView(imgWeekView); //whole activity layout
//Test
cnvWeekView.DrawColor(new Color(128, 128, 128));
Paint paint = new Paint(PaintFlags.AntiAlias);
paint.Color = new Color(255, 255,0);
cnvWeekView.DrawCircle(50, 50, 40, paint);
Finally I found a way how to measure my ImageView and here I will post my answer.
I believed that there should be much easier solution, but maybe there isn't. From this question I took most of the important data:
How to get the width and height of an android.widget.ImageView?
Things look however a little different in my android application and I'm not experienced enough to tell why. I had to change things a little. I had to learn a bit about interfaces and this question helped too.
Implementing the View.IOnTouchListener interface
Here is how I combined things. First I created class that will do the measure.
public class MyPredrawListener : Java.Lang.Object, ViewTreeObserver.IOnPreDrawListener
{
ImageView imageView;
public MyPredrawListener(ImageView img)
{
imageView = img;
}
public bool OnPreDraw()
{
imageView.ViewTreeObserver.RemoveOnPreDrawListener(this);
int finalHeight = imageView.MeasuredHeight;
int finalWidth = imageView.MeasuredWidth;
Bitmap bitmap = Bitmap.CreateBitmap(finalWidth, finalHeight, Bitmap.Config.Argb8888);
imageView.SetImageBitmap(bitmap);
//Test to see result
Canvas cnv = new Canvas(bitmap);
Paint paint = new Paint();
paint.Color = new Color(255, 255, 0);
cnv.DrawColor(new Color(128, 128, 128));
cnv.DrawCircle(finalWidth-50, finalHeight-50, 50, paint);
return true;
}
}
And in code where I create my imageView I set the listener like this.
imgWeekView = new ImageView(context);
MyPredrawListener listener=new MyPredrawListener(imgWeekView);
imgWeekView.ViewTreeObserver.AddOnPreDrawListener(listener);
In OnPreDraw function I put test code to see the result graphically, clearing bitmap to gray color and painting yellow circle to bottom right of a view.

How to add Images to CListCtrl in MFC

How do you add Images to a ClistCtrl in MFC? I have tried and found that it's quite difficult.
I used CImageList to add images and then passed it to the CListCtrl. Can you provide some samples?
m_sentToCListCtrl.InsertColumn(0, _T("Item Name"), LVCFMT_LEFT,nColInterval*3);
m_sentToCListCtrl.InsertColumn(1, _T("Value"),LVCFMT_LEFT, nColInterval);
m_sentToCListCtrl.InsertColumn(2, _T("Time"), LVCFMT_LEFT, rect.Width()-4*nColInterval);
ListView_SetExtendedListViewStyle(m_sentToCListCtrl.m_hWnd,LVS_EX_CHECKBOXES );
// Create 256 color image lists
HIMAGELIST hSentToList =ImageList_Create(84,71, ILC_COLOR8 |ILC_MASK , 8, 1);
m_sentToImageList.Attach(hSentToList);
You need to add some bitmaps to your CImageList after you have created it. Something like this:
m_myImageList.Create(84,71, ILC_COLOR8 |ILC_MASK , 8, 1);
CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
m_myImageList.Add(&bm, RGB(0, 0, 0));
bm.LoadBitmap(IDB_BITMAP2);
m_myImageList.Add(&bm, RGB(0, 0, 0));
Then, attach it to the CListCtrl:
m_sentToCListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
Finally, you add items to your CListCtrl by using the InsertItem method:
LVITEM lvItem;
lvItem.iItem = 0;
lvItem.iImage = 0; // image index that refers to your image list
lvItem.pszText = L"Item 1";
lvItem.mask = LVIF_TEXT;
m_sentToCListCtrl.InsertItem(&lvItem);
For more info refer to CListCtrl documentation. There are examples too.

MonoTouch UIButton Gradient Covers Title

I have a similar problem to this post (UIButton: Add gradient layer and title is not shown anymore - how to fix?) but his solution did not work for me. First things first, I'm somewhat new to MonoTouch, but have never gone as far as customizing the out of the box controls.
I am trying to add a gradient to my button, but when I do so, the gradient looks exactly as I want, but the text is covered (I set the opacity of my gradient to .5 to test). I have a storyboard in which I have visually designed the interface, but want to tweak a few things.
Here is my code:
var gradient = new CAGradientLayer();
gradient.Frame = getStartedButton.Layer.Bounds;
gradient.Colors = new MonoTouch.CoreGraphics.CGColor[]
{
UIColor.FromRGB (23, 55, 94).CGColor,
UIColor.FromRGB (33, 81, 141).CGColor
};
getStartedButton.Layer.AddSublayer(gradient);
getStartedButton.Layer.CornerRadius = 10;
getStartedButton.Layer.BorderColor = UIColor.White.CGColor;
getStartedButton.Layer.BorderWidth = 1;
getStartedButton.VerticalAlignment = UIControlContentVerticalAlignment.Center;
getStartedButton.Font = UIFont.FromName("Helvetica", 12);
getStartedButton.SetTitleColor(UIColor.White, UIControlState.Normal);
getStartedButton.SetTitle("Get Started", UIControlState.Normal);
Embarrassing, but it was simply a matter of changing the type of button to custom in XCode.

iOS 5 SDK UITextView limitation / bug?

I have a UITextView with a lot of text in it. When the subview containing the UITextView is shown the UITextView only appears after the UITextView has been touched and scrolled.
Is there a limit of how much text can be in a UITextView?
Or is this a bug?
attached is a clip explaining this occurrence.
https://dl.dropbox.com/u/8256776/UITextView%20Bug.MOV
Ok, I have looked into it and it seems to be quite a common issue. It seems that the text view doesn't feel that it has to draw the text, but calling setNeedsDisplay doesn't help. I don't know if there is a "real" solution, but you can force it to draw the text by scrolling programmatically:
disclaimerView.contentOffset = CGPointMake(0, 1);
disclaimerView.contentOffset = CGPointMake(0, 0);
An unrelated thing in your code: In your switchView method you have two animations, one for the menu view and one for the view you are sliding into place. This is unnecessary as you can put both setFrame calls in the same animation:
MenuView = (UIView *)[self.view viewWithTag:100];
appView = (UIView *)[self.view viewWithTag:ViewInt];
[MenuView setFrame:CGRectMake(0, 0, 320, 480)];
[appView setFrame:CGRectMake(321, 0, 320, 480)];
[UIView beginAnimations:#"move buttons" context:nil];
[UIView setAnimationDuration:.5];
[MenuView setFrame:CGRectMake(-320, 0, 320, 480)];
[appView setFrame:CGRectMake(0, 0, 320, 480)];
disclaimerView.contentOffset = CGPointMake(0, 1);
disclaimerView.contentOffset = CGPointMake(0, 0);
[UIView commitAnimations];
And one more thing (and then I will back off :) )
You seem to be quite fond of using tags to retrieve elements. While it does work, it is not very understandable. You don't have that many elements so I would just add each of them as IBOutlet with a meaningful name (like you did with your disclaimerView). Also, have seperate switchView methods for the different views you are moving into place. That way you can easily perform additional stuff you might need for just that view, like the force scroll on disclaimerView.

Buttons in LinearLayout not filling entire space programmatically

So I have a LinearLayout in horizontal mode which I add buttons to at random times in code and I like them all to fill up the space equally.
This is my current code so far:
layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.FILL;
and I add it to my view here:
linearLayout.addView(button, layoutParams);
All it does is add the buttons as if it was wrap_content and not expanding their width to fill up the available space as in the buttons look left justified.
I also have tried linearLayout.setGravity(Gravity.FILL_HORIZONTAL); and
linearLayout.setWeightSum(++weightSum);
linearLayout.addView(button, layoutParams);
where layoutParams in this case is:
layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT, 1);
I also tried setting the layout width to zero per answers to other questions.
Am I missing another technique?
Edit: I figured it out, I forgot to set the width of the LinearLayout to match_parent instead of wrap_content.
Button's background has "margins" so they will always have gaps even if there's no space between buttons. You have to change background to your own image which doesn't have these margins.
EDIT: You should use weights for buttons.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
0, LayoutParams.WRAP_CONTENT);
params.weight = 1;
for( int i = 0; i < 5; ++i) {
Button button = new Button(this);
button.setText("Button" + (i + 1));
linearLayout.addView(button, params);
}

Resources