前面几个模式scaleToFill/scaleAspectFit/scaleAspectFill经常会在对于图片的控制上的时候,后的位置关系其实我们对于一些关系定义的时候就可以使用了.
extension UIView {
public enum ContentMode : Int {
case scaleToFill
case scaleAspectFit // contents scaled to fit with fixed aspect. remainder is transparent
case scaleAspectFill // contents scaled to fill with fixed aspect. some portion of content may be clipped.
case redraw // redraw on bounds change (calls -setNeedsDisplay)
case center // contents remain same size. positioned adjusted.
case top
case bottom
case left
case right
case topLeft
case topRight
case bottomLeft
case bottomRight
}
}
纵向抑或横向,我已经看见太多的自定义控件中定义这个枚举,孰不知其实系统早就有了.
extension NSLayoutConstraint {
public enum Axis : Int {
case horizontal
case vertical
}
}
一般倒角的函数会使用这个枚举,其实这个枚举不仅在于使用,更是告诉我们如何定义一个有做个选项的枚举的范例(使用OptionSet协议).
public struct UIRectCorner : OptionSet {
public init(rawValue: UInt)
public static var topLeft: UIRectCorner { get }
public static var topRight: UIRectCorner { get }
public static var bottomLeft: UIRectCorner { get }
public static var bottomRight: UIRectCorner { get }
public static var allCorners: UIRectCorner { get }
}
网友评论