您的位置:首页 > 移动开发 > Swift

关于 Swift segmentController 去掉边框的方法

2016-04-28 16:36 387 查看
func setNav() {

let segmentTitles = ["aaa",
"bbb", "ccc"]

// segment 去边框颜色

self.segment =
UISegmentedControl(items: segmentTitles)

// 先去除边框颜色

self.segment.tintColor =
UIColor.clearColor()

// 设置一个字体的字典,内容为没点击的字体大小和颜色

let unselectedTextAttributes:
NSDictionary = [NSFontAttributeName:
UIFont.boldSystemFontOfSize(16),
NSForegroundColorAttributeName:
UIColor ( red: 0.604, green:
0.5857, blue: 0.5528, alpha:
1.0 )];

self.segment.setTitleTextAttributes(unselectedTextAttributes
as [NSObject :
AnyObject], forState:
UIControlState.Normal)

// 点击之后的字体大小和颜色

let selectedTextAttributes:
NSDictionary = [NSFontAttributeName:
UIFont.boldSystemFontOfSize(16),
NSForegroundColorAttributeName:
UIColor ( red: 0.3915, green:
0.6216, blue: 1.0, alpha:
1.0 )]

self.segment.setTitleTextAttributes(selectedTextAttributes
as [NSObject :
AnyObject], forState:
UIControlState.Selected)

// 添加到导航栏

self.navigationItem.titleView =
self.segment

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: