UI控件常用设置之直接粘贴使用swfit版

版权声明:最短的时间最核心的知识,有疑问,欢迎进行留言。 https://blog.csdn.net/lizhidefengzi/article/details/83869335

常用控件设置

  1. UILable
  2. UIButton
  3. UITableViewController
  4. 常用宏设置

UILabel

常见设置:

  1. 设置换行
  2. 设置对齐方式
 lazy private var messageTitleLabel: UILabel = {
    let label = UILabel()
    label.textColor = UIColor.black
    label.backgroundColor = .clear
    label.textAlignment = NSTextAlignmentCenter;
    label.font = UIFont.systemFont(ofSize: 10)
    label.numberOfLines = 0
    return label
}()

UIButton

常见设置:

  1. 设置圆角、边框样式
  2. 设置图片与标题相对位置
    lazy private var button: UIButton = {
        let button = UIButton(type: .custom)
        button.backgroundColor = .clear
        button.setTitle("详情", for: .normal)
        button.imageEdgeInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 50)
        button.titleEdgeInsets = UIEdgeInsets.init(top: 0, left: -50, bottom: 0, right: 0)
        button.setTitleColor(.orange, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 10)
        
        copyButton.layer.cornerRadius = 10
        copyButton.layer.masksToBounds = true
        copyButton.layer.borderColor = UIColor.orange.cgColor
        copyButton.layer.borderWidth = 1.0
        return button
    }()

UITableViewController

常见设置问题

  1. UITableViewCell重用
  2. 取消分割线,取消点击跳转
  3. 设置右侧细节
  4. 添加分割线,行之间距离(默认没有方法,添加对应view视图即可)
	self.selectionStyle = .none
	self.tableView.separatorStyle = .none
	self.tableView.register(WMCommunitySendCodeTableViewCell.self, forCellReuseIdentifier: "cell")

常用宏设置

  1. 颜色设置
  2. 相对距离设置
func RGB(r: CGFloat, g: CGFloat, b: CGFloat, alpha: CGFloat) -> UIColor {
    return UIColor (red: r/225.0, green: g/225.0, blue: b/225.0, alpha: alpha)
}

func kScale(_ num: CGFloat) -> CGFloat {
    return num * screenWidth / 375
}

生命周期

ios开发生命周期分UIViewController生命周期App的生命周期,掌握的意义在于熟悉程序的执行过程。
生命周期

猜你喜欢

转载自blog.csdn.net/lizhidefengzi/article/details/83869335