美文网首页Swift&Objective-CiOS程序猿Swift
swift——一些有用的小Tips

swift——一些有用的小Tips

作者: Bart_Simpson | 来源:发表于2018-07-24 14:46 被阅读32次

UITableView

  • 有时候UI需要tableView距离上方的元素间隙为0,加上这段代码就行
    self.tableView.tableHeaderView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 0, height: CGFloat.leastNormalMagnitude))

  • UI会设计出各种颜色的箭头,如下图。


    向右的箭头为蓝色

    一般情况都会选择自定义Cell,但是Cell特别简单完全不想自定义,就可以自定义accessoryView,上代码。

cell.accessoryType = .none
cell.accessoryView = getBlueRightArrow()

func getBlueRightArrow() -> UIView{
        let vi = UIImageView.init(frame: CGRect.init(x: 0, y: 14, width: 16, height: 16))
        vi.image = UIImage.init(named: "mine_RightArrow")
        return vi
}

上图就是用这种方法实现的效果。

  • 将section的footer、header 之间的间隙设置为透明色,保证与背景色一致
    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        
        view.tintColor = UIColor.clear
        
    }
    
    func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
        
        view.tintColor = UIColor.clear
        
    }

UITextField

  • 修改placeholder的字体颜色和大小
    field.attributedPlaceholder = NSAttributedString.init(string:"蓝色且字体大小为15的请输入", attributes: [NSForegroundColorAttributeName:UIColor.blue, NSFontAttributeName:UIFont.systemFont(ofSize:15)])

关于Label的富文本可以去看看这个swift——富文本文字的简单使用

后续的各种小Tips会陆续更新上来!大家如果有什么Tips也可以留言给我,互勉!

相关文章

网友评论

    本文标题:swift——一些有用的小Tips

    本文链接:https://www.haomeiwen.com/subject/bkpjmftx.html