码迷,mamicode.com
首页 > 编程语言 > 详细

Swift与OC代码转换实例

时间:2015-10-07 12:09:40      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:

1.

Objectice-C code:

 1 NSShadow *shadow = [NSShadow new];
 2 
 3 [shadow setShadowColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]];
 4 
 5 [shadow setShadowOffset:CGSizeMake(0, 1)];
 6 
 7 NSDictionary *attributes = @{
 8 
 9                                 NSForegroundColorAttributeName: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0],
10 
11                                 NSShadowAttributeName: shadow,
12 
13                                 NSFontAttributeName: [UIFont fontWithName:@"AmericanTypewriter" size:16.0]
14 
15                              };
16 
17 [self.navigationItem.rightBarButtonItem setTitleTextAttributes:attributes forState: UIControlStateNormal];
18 
19 // Or you can use.
20 
21 [[UIBarItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];

Swift Code:

// Bar title text color

let shadow = NSShadow()

shadow.shadowColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)

shadow.shadowOffset = CGSizeMake(0, 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 = [

                        NSForegroundColorAttributeName : color,

                        NSShadowAttributeName : shadow,

                        NSFontAttributeName : titleFont

                 ]

self.navigationItem.rightBarButtonItem?.setTitleTextAttributes(attributes, forState: UIControlState.Normal)

// Or you can use

UIBarItem.appearance().setTitleTextAttributes(attributes, forState: UIControlState.Normal)

 

Swift与OC代码转换实例

标签:

原文地址:http://www.cnblogs.com/abelsu/p/4858443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!