English 中文(简体)
你们如何使用套 标题TextAttributes:forState in UIBarItem?
原标题:How do you use setTitleTextAttributes:forState in UIBarItem?

您如何使用<条码>查询指南>。

您如何制定<条码> NSDictionary ? 做不到这一点,它的工作和文件也非常清楚。

www.un.org/Depts/DGACM/index_spanish.htm 文件:

setTitleTextAttributes:forState:

www.un.org/Depts/DGACM/index_spanish.htm 规定某一控制国的标本:

- (void)setTitleTextAttributes:(NSDictionary *)attributes 
                      forState:(UIControlState)state

参数:

属性: 字典含有文本属性的关键价值。 您可利用国家情报和安全局的增补资料中列举的钥匙,具体说明字体、字面图和文字影子。

声明:你想要确定标题的案文属性的控制状态。

最佳回答

例:

[[UIBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0], UITextAttributeTextColor, 
[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor, 
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
[UIFont fontWithName:@"AmericanTypewriter" size:0.0], UITextAttributeFont, nil] 
forState:UIControlStateNormal];
问题回答

<>Swift 5.0:

// Bar title text color
let shadow = NSShadow()
shadow.shadowColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
shadow.shadowOffset = CGSize(width: 0, height: 1)
let color : UIColor = UIColor(red: 220.0/255.0, green: 104.0/255.0, blue: 1.0/255.0, alpha: 1.0)
let titleFont : UIFont = UIFont(name: "AmericanTypewriter", size: 16.0)!

let attributes = [
    NSAttributedString.Key.foregroundColor : color,
    NSAttributedString.Key.shadow : shadow,
    NSAttributedString.Key.font : titleFont
]
self.navigationItem.rightBarButtonItem?.setTitleTextAttributes(attributes, for: .normal)

// Or you can use
UIBarItem.appearance().setTitleTextAttributes(attributes, for: .normal)

<>Swift 4.0:

// Bar title text color
let shadow = NSShadow()
shadow.shadowColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
shadow.shadowOffset = CGSize(width: 0, height: 1)
let color : UIColor = UIColor(red: 220.0/255.0, green: 104.0/255.0, blue: 1.0/255.0, alpha: 1.0)
let titleFont : UIFont = UIFont(name: "AmericanTypewriter", size: 16.0)!

let attributes = [
        NSAttributedStringKey.foregroundColor : color,
        NSAttributedStringKey.shadow : shadow,
        NSAttributedStringKey.font : titleFont
    ]

self.navigationItem.rightBarButtonItem?.setTitleTextAttributes(attributes, for: UIControlState.normal)
// Or you can use
UIBarItem.appearance().setTitleTextAttributes(attributes, for: UIControlState.normal)

www.un.org/Depts/DGACM/index_spanish.htm 目标C代码:

NSShadow *shadow = [NSShadow new];
[shadow setShadowColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]];
[shadow setShadowOffset:CGSizeMake(0, 1)];

NSDictionary *attributes = @{
                                NSForegroundColorAttributeName: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0],
                                NSShadowAttributeName: shadow,
                                NSFontAttributeName: [UIFont fontWithName:@"AmericanTypewriter" size:16.0]
                             };

[self.navigationItem.rightBarButtonItem setTitleTextAttributes:attributes forState: UIControlStateNormal];

// Or you can use.

[[UIBarItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];

Here s phix23 s code, just with an updated, and I think cleaner, syntax:

[[UIBarItem appearance] setTitleTextAttributes:@{
                      UITextAttributeTextColor: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0],
                UITextAttributeTextShadowColor: [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0],
               UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
                           UITextAttributeFont: [UIFont fontWithName:@"AmericanTypewriter" size:0.0]}
                                      forState: UIControlStateNormal];
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIColor whiteColor], nil] forKeys:[NSArray arrayWithObjects:UITextAttributeTextColor, nil]] forState:UIControlStateNormal];

<>http://www.unf.org/>。

let attributes = [
    NSAttributedString.Key.foregroundColor : UIColor.orange,
    NSAttributedString.Key.font : UIFont.systemFont(ofSize: 20)
]
vc.tabBarItem.setTitleTextAttributes(attributes, for: .normal)




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签