Swift 学习记录--2

前端之家收集整理的这篇文章主要介绍了Swift 学习记录--2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1、在UIView 上面 拖上 navigationBar,navigationItem,BarButtonItem
    @IBOutlet weak var navTitle: UINavigationItem!
    
    @IBOutlet weak var navBar: UINavigationBar!
    @IBOutlet weak var settingBtn: UIBarButtonItem!

		//设置navigation 背景颜色 为透明
        navBar.setBackgroundImage(UIImage(),forBarMetrics: UIBarMetrics.Default)
        navBar.shadowImage = UIImage()
        navBar.translucent = true  
		//设置navigation 显示层为 绿色
        let greenColor:UIColor = UIColor(red:75/255,green: 163/255,blue: 75/255,alpha:1)
        navBar.layer.backgroundColor=greenColor.CGColor
        //设置 tite 的字体和颜色
        navBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor(),NSFontAttributeName: UIFont(name:"Helvetica",size:22.0)!]
        
        //设置nav button 为图标
        settingBtn.tintColor=UIColor.whiteColor()
        settingBtn.setTitleTextAttributes([NSFontAttributeName:FontAwesomeIcon.getFontAwesome(18)],forState: UIControlState.Normal)
        settingBtn.title=FontAwesomeIcon.getFontICO("fa-cog")
        //设置 SearchBar
        let searchBar:UISearchBar = UISearchBar(frame: CGRectMake(0,150,20))
        searchBar.placeholder = "搜索实验..."
        let rightNavBarButton = UIBarButtonItem(customView:searchBar)
        navTitle.rightBarButtonItem = rightNavBarButton


2. swift中使用 FontAwesome添加 FontAwesome.ttf 和 相应的.swift 文件

注意在info.plist 中添加 Fonts provided by application 并添加 item 的值为 FontAwesome.ttf

原文链接:https://www.f2er.com/swift/326133.html

猜你在找的Swift相关文章