How to change font size and font name of uisegmentedcontrol programmatically? I used swift.
Here is my code:
self.mysegmentedControl = UISegmentedControl(items: [ NSLocalizedString("Aaaaaa", comment: ""), NSLocalizedString("Bbbbbb", comment: ""), NSLocalizedString("Cccccc", comment: ""), NSLocalizedString("Dddddd", comment: ""), NSLocalizedString("Eeeeee", comment: ""), ]) self.mysegmentedControl.addTarget(self, action: "mysegmentedControlDidChange:", forControlEvents: .ValueChanged) self.mysegmentedControl.selectedSegmentIndex = 0
regards.
Change Font And Size Of UILabel In StoryboardXIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.
Press xcode->preferences. select fonts and colors. select ANY font in the list and press cmd+a (select all fonts) select font size for all editor fonts at the bottom of the window.
There are two ways to set a font size for Text view in SwiftUI. Fixed font size stays the same regardless of user preference. To set fixed font size, we specified the size we wanted at a time when we created a font. We can set this for both the system font and a custom font. We create a system font with Font.system (size:weight:design:) method.
Text ( "Simple Swift Guide" ). font (. headline ). bold (). italic () Text ( "Simple Swift Guide" ). font (. callout ). foregroundColor (. blue) In a second, more advanced tutorial, we’re going to learn how to use custom font family in your iOS app.
To set a different font on UIButton programmatically you will need to create a new instance of UIFont object. The initializer of UIFont accepts two arguments: name and size. where the “GillSans-Italic” is a font name you want to set.
The default iOS font is called San Francisco and if you don’t explicitly change it, then all of your text will have the default iOS look. Use one of many standard fonts which are great to keep consistency with default iOS look: Some other options of standard fonts include: title, headline, subheadline, body, callout, caption or footnote.
UI can use control appearance, best place to add it is in app delegate, didFinishLaunchingWithOptions
method, use this if you want to set up the same attribute to every UISegmentedControls in your project just once:
let attr = NSDictionary(object: UIFont(name: "HelveticaNeue-Bold", size: 16.0)!, forKey: NSFontAttributeName) UISegmentedControl.appearance().setTitleTextAttributes(attr as [NSObject : AnyObject] , forState: .Normal)
But if you are going to set up attributes to just one UISegmentedControl or if you want to change it more often base on some condition use this, UISegmentedControl method:
func setTitleTextAttributes(_ attributes: [NSObject : AnyObject]?, forState state: UIControlState)
Example:
let attr = NSDictionary(object: UIFont(name: "HelveticaNeue-Bold", size: 16.0)!, forKey: NSFontAttributeName) seg.setTitleTextAttributes(attr as [NSObject : AnyObject] , forState: .Normal)
For Swift 4
let font: [AnyHashable : Any] = [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 17)] segmentedControl.setTitleTextAttributes(font, for: .normal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With