UI
- 自定义组件
自定义组件要同事兼容代码初始化和xib初始化,需要同时执行下面两个方法
// frame 初始化执行
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
// xib初始化执行
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupUI()
}
-
UICollectionView 添加footer 后被遮挡
可能的解决办法
1.试试调整collectionView的frame,将底部的间距调大
2.试试调整collectionView的contentInset,将bottom调大
_collectionView.contentInset = UIEdgeInsetsMake(0, 0,49, 0);
自定义组件类,在菜单中行设置属性 ,用@IBInspectable修饰,使用时直接拖控件,然后xib绑定此类就好
@IBDesignable
open class VCShadowView: UIView {
@IBInspectable public var cornerRadius: CGFloat = 6.0 {
didSet {
_contentView.layer.cornerRadius = cornerRadius
self.layer.cornerRadius = cornerRadius
}
}
@IBInspectable public var shadowColor: UIColor = .gray {
didSet {
self.layer.shadowColor = shadowColor.cgColor
}
}
@IBInspectable public var shadowRadius: CGFloat = 5.0 {
didSet {
self.layer.shadowRadius = shadowRadius
}
}
@IBInspectable public var shadowOpacity: Float = 0.09 {
didSet {
self.layer.shadowOpacity = shadowOpacity
}
}
@IBInspectable public var shadowOffset: CGSize = CGSize(width: 0, height: 2.0) {
didSet {
self.layer.shadowOffset = shadowOffset
}
}
let _contentView = UIView()
var contentView: UIView {
return _contentView
}
override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
fileprivate func initialize() {
backgroundColor = .clear
addSubview(_contentView)
_contentView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
_contentView.backgroundColor = .white
_contentView.clipsToBounds = true
_contentView.layer.cornerRadius = cornerRadius
}
override open func draw(_ rect: CGRect) {
super.draw(rect)
self.layer.shadowColor = shadowColor.cgColor
self.layer.shadowOffset = shadowOffset
self.layer.shadowRadius = shadowRadius
self.layer.shadowOpacity = shadowOpacity
self.layer.cornerRadius = cornerRadius
}
}
- 图片部分显示裁剪
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
Xcode
文件结构
语法类
-
NSUserDefaults 存储自定义类的时候
- 该类必修实现 NSCoding 协议
- 该类在存储的时候要要转换为NSData,自定义对象的数据或者字典雅瑶转换的NSData
- 简言之,偏好设置只能存储基本数据类型
swift Int64 等于 long
if var 和 if let 的关系
数组的 += 是什么操作
@discardableResult 注解是什么含义
URLQueryItem & URLQueryItem
数组的filter操作
框架类
Alamofire
- asURL
/// Returns a URL that conforms to RFC 2396 or throws an `Error`.
///
/// - throws: An `Error` if the type cannot be converted to a `URL`.
///
/// - returns: A URL or throws an `Error`.
规范类
1.swift 枚举
- 声明的名称首字母要大写,但是case 选项首字母要小写