I have following settings for my textfield
_urlSearchTextFieldFirst.backgroundColor = [UIColor clearColor];
_urlSearchTextFieldFirst.placeholder = #"url";
_urlSearchTextFieldFirst.delegate = self;
_urlSearchTextFieldFirst.keyboardType = UIKeyboardTypeURL;
_urlSearchTextFieldFirst.keyboardAppearance = UIKeyboardAppearanceDefault;
_urlSearchTextFieldFirst.returnKeyType = UIReturnKeyGo;
_urlSearchTextFieldFirst.autocorrectionType = UITextAutocorrectionTypeNo;
_urlSearchTextFieldFirst.autocapitalizationType = UITextAutocapitalizationTypeNone;
and the keyboard its displaying looks some old way some way zoomed.
You need to add iPhone X launch screen in asset folder .
Then Keyboard will work properly
And For layout
You need to use safe layout , Go to storyboard , Select ViewController to make safe layout which is compatible for iPhone X
Related
see above attached image.
It's programatically written in Objective-C. UISegmentController is cutting title text.
Weird thing is, it shows 'Privacy Policy' full text which is way longer than 'About' and 'Terms', which is cutting.
Can anybody please help in this?
code is given below:
UISegmentedControl *unitsPicker = [[UISegmentedControl alloc] initWithItems:#[#"About", #"Terms", #"Privacy Policy"]];
unitsPicker.frame = CGRectMake(0, CGRectGetMaxY(unitsLabel.frame) + kBottomPaddingConstant, CGRectGetWidth(_unitsContainer.frame), segmentHeightConstant);
unitsPicker.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
unitsPicker.selectedSegmentIndex = ![TemperatureUtility unitIsCelsius];
[unitsPicker addTarget:self action:#selector(onUnitPickerChanged:) forControlEvents:UIControlEventValueChanged];
unitsPicker.layer.cornerRadius = 5.0f;
unitsPicker.layer.borderColor = [UIColorFromRGB(0xE9E9E9) CGColor];
unitsPicker.layer.borderWidth = 1.0f;
unitsPicker.layer.masksToBounds = YES;
unitsPicker.clipsToBounds = YES;
[_unitsContainer addSubview:unitsPicker];
Try setting:
segmentedControl.apportionsSegmentWidthsByContent = YES;
From the docs:
If the value of this property is true, for segments whose width value is 0, the control attempts to adjust segment widths based on their content widths.
The default is false.
Swift 5 and 5+ Solution
Add
mySegmentController.apportionsSegmentWidthsByContent = true
inside viewDidLoad() {}
It is still working well in ios 7, UITextView is added to popover and displayed.
UITextView *textViewComment =[[UITextView alloc]init];
textViewComment.tag = 2001;
textViewComment.delegate = self;
textViewComment.frame=CGRectMake(15,60, 370,120);
textViewComment.contentInset = UIEdgeInsetsMake(5.0f, 5.0f, 5.0f, 0.0f);
[textViewComment setReturnKeyType:UIReturnKeyDone];
textViewComment.textAlignment = NSTextAlignmentLeft;
textViewComment.showsHorizontalScrollIndicator = NO;
textViewComment.bounces = NO;
textViewComment.layer.borderColor = [[UIColor lightGrayColor]CGColor];
textViewComment.layer.borderWidth =1.0f;
[textViewComment addSubview:commentPlaceHolderLabel];
[popupViewController.view addSubview:textViewComment];
On ios8 adding textViewComment.keyBoardType = UIKeyboardAlphabet, textViewComment.enable = YES; didnt help. I dont know what mistake I am making. Is this new sdk bug? or my bug?
Thanks in Advance
Are you working in the simulator ?
Because by default the hardware keyboard is selected and the simulator's won't show up.
You can change that by going into menu "Hardware" -> "Keyboard" and deselect "Connect Hardware Keyboard"
I'm working on example from "iOS Programming Cookbook", based on iOS 7. I need to create UITextField and add it to ViewController.
In ViewController.m I have:
- (void) viewDidLoad {
[super viewDidLoad];
[self createField];
}
- (void) createField {
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(20.0f, 35.0f, 280.0f, 30.0f)];
self.textField.translatesAutoresizingMaskIntoConstraints = NO;
self.textField.borderStyle = UITextBorderStyleRoundedRect;
self.textField.placeholder = #"Enter text to share";
self.textField.delegate = self;
[self.view addSubview:self.textField];
}
On screenshot from book textField appears in the middle of screen's width under the status bar, but when I run it textField appears on the top left corner of screen behind the status bar.
Maybe the problem is, that I run app on iPhone 6 simulator with iOS 8. But I don't know how to solve it.
Thanks!
Using self.textField.translatesAutoresizingMaskIntoConstraints = NO; is pretty much telling the object that it doesn't really care about the frame but relies more on the constraints that you give it. Setting it to YES takes the frame and automatically applies constraints to it to mimic the frame that you give it.
For example it would apply the constraints to have the frame appear at: CGRectMake(20.0f, 35.0f, 280.0f, 30.0f). When setting it to NO use NSLayoutConstraint and create the constraints programatically.
But in your case just remove the line
self.textField.translatesAutoresizingMaskIntoConstraints = NO;
because it is set to YES by default.
I have a button in my ios project which displays edit profile if the user is the current user and follow if the user is not the current user.
I am setting the titleLabel text programmatically dependant on the above condition. I am also programatically setting the button text to align center.
The problem I'm having is it works perfectly for the edit profile button which appears as it should center aligned but when showing the follow button the word follow is slightly off center to the left and I can't figure out where I'm going wrong.
Here is my code:
if([userID isEqualToString:credentialID]){
self.followEditBtn.layer.cornerRadius = 2;
self.followEditBtn.layer.borderColor = UIColorFromRGB(0xA6B9C1).CGColor;
self.followEditBtn.layer.borderWidth = 1.0f;
self.followEditBtn.layer.backgroundColor = UIColorFromRGB(0xF8FBFC).CGColor;
self.followEditBtn.titleLabel.textColor = UIColorFromRGB(0xA1B1C3);
self.followEditBtn.titleLabel.text = #"Edit Profile";
self.followEditBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
} else {
self.followEditBtn.layer.cornerRadius = 2;
self.followEditBtn.layer.borderColor = UIColorFromRGB(0x19A548).CGColor;
self.followEditBtn.layer.borderWidth = 1.0f;
self.followEditBtn.layer.backgroundColor = [UIColor whiteColor].CGColor;
self.followEditBtn.titleLabel.textColor = UIColorFromRGB(0x19A548);
self.followEditBtn.titleLabel.text = #"Follow";
self.followEditBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
}
And some images of the buttons as you can see the follow text is slightly off center to the left yet the edit profile button is correctly aligned:
I couldn't reproduce your problem (iOS 6.1 to 7.1). Although I had to make a small change in order to make it work, since it wasn't showing any text.
Instead of using:
self.followEditBtn.titleLabel.text = #"Edit Profile";
you should use:
[self.followEditBtn setTitle:#"Follow" forState:UIControlStateNormal];
I'm assuming you're using a UIButtonTypeCustom type UIButton, and having a fixed frame size.
I'd like you to tell me where are you putting this code, and how is this button being initialized.
_text = [[UITextField alloc] initWithFrame:CGRectZero];
_text.font = [Styles bodyFont];
_text.text = ((EditTextBubble *)(toEdit.bubble)).textLabel.text;
if ([_text.text isEqualToString:[#"E.g. " stringByAppendingString:((EditTextBubble *)toEdit.bubble).placeholder]]) _text.text = #"";
_text.textAlignment = NSTextAlignmentLeft;
_text.delegate = self;
_text.userInteractionEnabled = NO;
[self addSubview:_text];
_text.keyboardType = UIKeyboardTypeNumberPad;
I'm trying to get the number pad (http://cdn.arstechnica.net/wp-content/uploads/2013/09/keypad.png) to work for UITextField but all I get is the normal keyboard on the numbers page, not that google image above. How do you get it to work? This is on iOS 7 and on ipod/ipad, and without the nib file.
If you need to display a numpad keyboard on iPad, you will need to build your own (or use an open source), and set the text view's inputView to the view you created. But don't be alarmed, this is quite easy to do.
On iOS7, use UIInputView to get a similar look and background to the native keyboard.
An example of Apple's custom numeric keyboard on iPad in their Numbers app: