Change the font of a UIBarButtonItem

前端 未结 16 1136
春和景丽
春和景丽 2020-12-07 09:18

\"UIToolbar

I have a UIBarButtonItem in my UIToolbar titled

16条回答
  •  孤城傲影
    2020-12-07 09:47

    Swift3

      buttonName.setAttributedTitle([
            NSFontAttributeName : UIFont.systemFontOfSize(18.0),
            NSForegroundColorAttributeName : UIColor.red,NSBackgroundColorAttributeName:UIColor.black],
                                         forState: UIControlState.Normal)
    

    swift

       barbutton.setTitleTextAttributes([
            NSFontAttributeName : UIFont.systemFontOfSize(18.0),
            NSForegroundColorAttributeName : UIColor.redColor(),NSBackgroundColorAttributeName:UIColor.blackColor()],
            forState: UIControlState.Normal)
    

    Objective-C

         [ barbutton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
            [UIFont fontWithName:@"Helvetica-Bold" size:20.0], NSFontAttributeName,
            [UIColor redColor], NSForegroundColorAttributeName,[UIColor blackColor],NSBackgroundColorAttributeName,
            nil]
            forState:UIControlStateNormal];
    

提交回复
热议问题