I'm using some custom fonts I added to my project for the titles of UIButton. I am not able to set my custom fonts in IB, and I've read in some posts that it is not possible yet in the last XCode version, is that right? So, currently, I'm setting the font for the titles programmatically. The point is that, as in IB the font is set to the default, when I set my custom font programmatically it is not centered, I guess because the font I can see in IB for the button has another height and width and this is the size considered to center the title. How could I center the title with my custom font?
Thanks!
Try this.
[button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
The problem came from the custom font, that it introduced some space below characters. This post solved my problem:
UIButton custom font vertical alignment
Related
I have following button configured.
and this is how I configured it. it works fine with English.
I have setup localisation with my app and when new text load to button it looks like below
Note : I have setup fixed width constraint using autolayout for the button and relation to
Greater than or equal.
how to fix this. hope your help with this.
Handling Insets for having button and image displayed together is a pain to adjust. A more common approach would be:
Create a custom view
Add an image and label giving appropriate constraints within the custom view
Put a button on top with clear background color so as to make it transparent.
All the three views can should be children of the custom view.
Now using this custom view, you have the flexibility to adjust it as per your needs.
Hope this helps :)
You can fix this issue by adding a new UIImageView as a subview to the super-view of the UIButton and set the image. Add the constraints leading(to the trailing of UIButton), centreY(to centerY of UIButton), height and width(constant you like) constraint to the UIButton that you already have. And add a UITapGestureRecognizer and set the action provided for UIButton.
I am working on custom font,IRANSansMobile_Bold. This font unwanted bottom padding. can I change this bottom padding for entire application I have already use another font now it is not possible for me to add edgeInset in every control
In interfaceBuilder i have created a simple UILabel. It has text inside and i set it to attributedText. I'm not able to change the font size. Each time i try to change the font and run the program the font remains unchanged. In fact what i have tried is after i alter the font size and run the app and return to IB the font has been reset on its own !!
here are my IB settings for UILabel attributedText:
Select the text you want to modify
For example : Selected the "platinum" then reset font
Try this:
yourlabel.font = [yourlabel.font fontWithSize:16];
or
[yourlabel setFont:[UIFont systemFontOfSize:16]];
Setting the font size is better done in your code, typically in viewWillAppear or viewDidLoad methods.
This link --> HERE <-- has another way by creating a method to handle changing font size in attributed text. Not bad either.
I know that in code I can do [myButton.titleLabel setTextAlignment: NSTextAlignmentRight]; but how would I do this in Storyboard in User Defined Runtime Attributes?
You can set the alignment of content (text or image) within your UIButton in the Attributes Inspector Panel.
The menu is "Control", you can set Horizontal & Vertical Alignment
How to make UIButton's text alignment center? Using IB
This post shows how to do it in storyboard.
You can also adjust the constraints of the content, title or image in the size inspector of the button:
In my case, I was only able to really centralize the character "+" and "-" after setting a value for the bottom of the title.
I am trying to set the text in my UIButton programmatically, but the text becomes abbreviated when displayed in the button. Is there a way to adjust the font size of the text in the button to fit the width, through code? I have checked other questions, but the answers do not solve my problem. Thanks.
Add this line for button object:
button.titleLabel?.adjustsFontSizeToFitWidth = true
If you work with the titleLabel you can use UILabel's adjustsFontSizeToFitWidth
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UILabel_Class/index.html#//apple_ref/occ/instp/UILabel/adjustsFontSizeToFitWidth
and then use UILabel's minimumScaleFactor to set a minimum:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UILabel_Class/index.html#//apple_ref/occ/instp/UILabel/minimumScaleFactor