I have problem with UIButton title. For too long text I have set truncate tail option, but instead … text is just cut.
How enforce ellipsis to show on button?
Use this code
button.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
button.titleLabel.adjustsFontSizeToFitWidth = false;
Related
I want to make application in which i want to make a login screen. It has button having name "Log inn with Facebook". I want font size of Facebook greater than Log in with. How can I set it in main storyboard?Can anyone plz help me?
Follow these steps-
1.Select button
2.Change its type to custom in Attributes inspector
3.Change its title from Plain to Attributed
4.Change the part of title which you want to be set bold
A solution would be to have a UIView with two different UILabel as subviews ( your "Log in with" label and your "Facebook" label ).
Then, above this UIView you could have a UIButton with a white background and an alpha equal to 0.01 so the button would be touchable but invisible.
This UIButton would be the functional part of your UI.
NSMutableAttributedString *titleText = [[NSMutableAttributedString alloc] initWithString:#"Login with Facebook"];
[yourbutton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
// Set the font to bold from the beginning of the string to the ","
[titleText addAttributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName] range:NSMakeRange(0, 10)];
// Set the attributed string as the buttons' title text
[yourbutton setAttributedTitle:titleText forState:UIControlStateNormal];
Instead of creating NSAttributedString create NSMutableAttributedString then you can just set the string like this.
However, I've applied different patches still I'm not able to fix placeholder text position and text color for UISearchbar.
But when I type something, it's showing up at a proper place.
What's the reason?
This is how you can change the colour of your placeholder text:
UITextField *searchField = [self.searchBar valueForKey:#"searchField"];
searchField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:#"Some Text"];
UILabel *placeholderLabel = [searchField valueForKey:#"placeholderLabel"];
placeholderLabel.textColor = [UIColor blueColor];
As for the position, by default, placeholder text is vertically centre positioned in the UISearchBar. From your screenshot, it appears to me that there are few new line characters in the end of the text.
there's a category created on UITextField, inside it, the placeholder text is drawing. I just corrected the frame and now everything works fine, even that solve the color issue as well.
I have a UIButton and the text is centered within the button normally until the text string gets longer and it starts to scale down the size of the text. Then the text seems to stick to the bottom of the textField instead of staying centered in the button.
self.titleBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
self.titleBtn.titleLabel.minimumScaleFactor = .2;
[self.descriptionBtn setTitle:#"T" forState:UIControlStateNormal];
//works normally
but
[self.descriptionBtn setTitle:#"This a longer title" forState:UIControlStateNormal];
//is vertically lower than center
As noted here :)
You need to user baselineAdjustment propery of the UILabel
label.baselineAdjustment = UIBaselineAdjustmentAlignCenters
Swift 3
label.baselineAdjustment = .alignCenters
For Button
button.titleLabel?.baselineAdjustment = .alignCenters
I have a UIButton and a UITextView, now when I write something on textview and submit the button the textview content is showing over a UIView , but If I write in the text field and press enter and write in a new line and hit in the button the text is showing in one line , It is not recognizing the enter . How do I recognize "enter" in UITextView and show the text in new line ??
-(IBAction)Acceptmethodtext:(id)sender
{
textwritingoverit= [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 100, 100)];
textwritingoverit.lineBreakMode = NSLineBreakByWordWrapping;
textwritingoverit.numberOfLines = 0;
textwritingoverit.text=imagelabeltext.text;
[imagecross addSubview:textwritingoverit];
}
where textwritingoverit is UILabel,
imagelabeltext is UITextView and
imagecross is UIView
Above I have edited my question
For textwritingoverit whenever I have text of single line it took multiple line as the width of the label is fixed but I need the text to be shown in multiple line when user add new line through UITExtview. I need flexible width of the label depending upon the text.
can anyone help me in this , how could i do so ..
Thanks
Check out: You might missed the numberOfLines property for the UILabel .
For Ex:
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;
I have a problem when setting a uibutton property:
[self.btnName.titleLabel setFont:[UIFont fontWithName:#"gillsansstd" size:16.0]];
It will disturb the text alignment, text shows top of button.
Why does setFont disturb the text alignment of uibutton?
Following Code set center (horizontally) of Alignment of UIButton titile .
myButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
Other Way
[myButton.titleLabel setTextAlignment:UITextAlignmentCenter];
This is what you need.
[btnName.titleLabel setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
You can vertically align the text in a button.
Choose Edge Inset from xib file.