Adding uiTextfield in UiviewController correctly - xamarin.ios

I am learning IOS using Xamarin. I am facing a problem of adding new uitextfield in my viewcontroller. I tried to find a solution but after 4 hours research didn't find anything.
Without adding uitextfield, viewcontroller shows all controls but when I add uitextfield, viewcontroller become blanks. Following is the uitextfield code:
UITextField txtUserame = new UITextField(new CGRect(70, 130, 150, 50));
txtUserame.Placeholder = "Username";
txtUserame.KeyboardType = UIKeyboardType.Default;
txtUserame.BecomeFirstResponder();
txtUserame.VerticalAlignment = UIControlContentVerticalAlignment.Center;
this.View.AddSubview(txtUserame);
How can I fix such behaviour?

Related

navigation background image xamarin ios

I'm new in xamarin(start using 2 week), now I need do a background Image wtih navigation bar like below picture? how can I do it?
You need to add an UIImage in your UIViewController (filling whole or only top of ViewController) setting your UINavigationBar to a clear color with
YourNavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
YourNavigationBar.ShadowImage = new UIImage();
YourNavigationBar.Translucent = true;
YourNavigationBar.BackgroundColor = UIColor.Clear;
To reset UINavigationBar transparency you have to use:
YourNavigationBar.SetBackgroundImage(null, UIBarMetrics.Default);

Custom controls not visible in the View

Below is my code I used to create a custom UITextField in code behind.
UITextField usernameField;
usernameField = new UITextField
{
Placeholder = "Enter your username",
BorderStyle = UITextBorderStyle.RoundedRect,
Frame = new RectangleF(10, 32, 50, 30)
};
View.AddSubview(usernameField);
But when I run my app, I dont see this anywhere. Not only this control but all the controls that I create in code behind.
If I drag the controls from toolbox onto my View it's working very fine.
What might be the cause?
Make sure that Container View is not transparent so Alpha = 1 and set background colors for appropriate controlls. Because by default its set to ClearYou can use this method to easly set background and rounded corners like in older versions of iOS
public static void MakeViewRounded(UIView view,float cornerRadius, MonoTouch.CoreGraphics.CGColor backgroundColor)
{
view.Layer.CornerRadius = cornerRadius;
view.Layer.BackgroundColor = backgroundColor;
}
Also make sure that you adding your custom controll to ViewController/View

UItextview will disregard line height when NSFontAttributeName is set

Well, Ive searched in several places and although some people allegedly have found fixes it doesn't seem to apply to my case.
I'm trying to procedurally set the line height of a few UItextviews like this :
UITextView *lab = [LocalTexts objectAtIndex:j];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineHeightMultiple = 50.0f;
paragraphStyle.maximumLineHeight = 50.0f;
paragraphStyle.minimumLineHeight = 50.0f;
NSString *string = lab.text;
NSDictionary *ats = #{
NSFontAttributeName : [UIFont fontWithName:#"DIN Medium" size:16.0f],
NSParagraphStyleAttributeName : paragraphStyle,
};
lab.attributedText = [[NSAttributedString alloc] initWithString:string attributes:ats];
Strange thing is that if I disable the NSFontAttributeName assignment, the line height will work, also, if I set the Paragraph style to have a certain paragraph height, that always works too, so the NSParagraphStyleAttribute IS NOT being fully ignored. I dont know if it is a bug or I'm actually doing something wrong.
I tried implementing it as pure CORE TEXT, but it is a bit too complex for the current scope of the project.
Hope someone can point me in the right direction. Thanks.
This is a known bug in NSHTMLWriter which is used by UITextView to convert your attributed string to HTML: http://www.cocoanetics.com/2012/12/radar-uitextview-ignores-minimummaximum-line-height-in-attributed-string/
You can use UITextView replacement we have in DTCoreText to render this text correctly: https://github.com/Cocoanetics/DTCoreText

TextField dissapear in TableLayout in LWUIT Java ME

I've searched for this problem but still can not find the solution. By the way my level of Google Translate is ugly (I speak Spanish). Well, the thing is that I want my application form looks as follows:
Or maybe so:
The problem is that when I want to, text fields disappear
I do not know why is that.
Here is my code:
TableLayout tableLayout = new TableLayout(3, 2);
this.setLayout(tableLayout);
//this.addCommandListener(this);
TableLayout.Constraint colum1 = tableLayout.createConstraint();
colum1.setWidthPercentage(35);
lblCodigo = new Label("Codigo :");
this.addComponent(colum1, lblCodigo);
TableLayout.Constraint colum2 = tableLayout.createConstraint();
colum2.setHorizontalAlign(Component.LEFT);
colum2.setWidthPercentage(65);
txtCodigo = new TextField();
this.addComponent(colum2, txtCodigo);
TableLayout.Constraint span = tableLayout.createConstraint();
span.setWidthPercentage(100);
span.setHorizontalAlign(Component.CENTER);
span.setHorizontalSpan(2);
btnBuscar = new Button("Buscar");
//btnBuscar.setPreferredW(50);
this.addComponent(span, btnBuscar);
Well, I'm working with LWUIT 1.4, Java ME SDK 3.0.
I tried that with LWUIT 1.5.
Does anyone have an idea why the text boxes disappear?

problem: menu does not show in cocos2d layer

I am trying to add menu to a layer in cocos2d but it just does not appear. Here's the code which is written in init method of a layer
CCMenuItem *aButton = [CCMenuItemImage itemFromNormalImage:#"btnImg.png" selectedImage:#"btnImgSel.png" target:self selector:#selector(buttonPressed:)];
aButton.position = ccp(60.0,30.0);
CCMenu *aMenu = [CCMenu menuWithItems:aButton, nil];
aMenu.position = ccp(500.0,20);
[self addChild:aMenu];
Nothing is overlapping the position i specified for menu. Is anything wrong in the code?
Try like these:-
CCLayer *menuLayer1 = [[[CCLayer alloc] init]autorelease];
[self addChild:menuLayer1];
CCMenuItemImage *startButton1 = [CCMenuItemImage
itemFromNormalImage:#"Play.png"
selectedImage:#"Play.png"
target:self
selector:#selector(Play:)];
CCMenu *menu1 = [CCMenu menuWithItems: startButton1,nil];
menu1.position = ccp(157,157 );
[menu1 alignItemsVertically ];
[menuLayer1 addChild: menu1];
For those who are facing an irritating situation where the code is right but menu items are not showing then check the image file. I was using .png images and they were refusing to be displayed. There was something internally wrong with the file, so I replaced that file and it solved the problem :)
Is the iPad your target platform? If so the "menu" should appear at the bottom of the screen. To display the Menu on iPhone adjust the "a.Menu.position" to anything lower than 480 in the first attribute of ccp

Resources