我使用下一个代码:
- (void)viewDidLayoutSubviews
{
[self initUIfeatures];
}
- (void)initUIfeatures
{
[authTextField setMaskByRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft) withCornerRadius:8.0f];
}
但现在我看到了这种奇怪的效果。
在didlayoutsubviews之后,我从viewcontroller调用它。我这样做是为了主线程更新。
datebin
问题是圆角落入。
答案 0 :(得分:1)
答案 1 :(得分:0)
我已经制作了相同的自定义类。您可以使用下面的代码,任何可以根据需要更改故事板和您想要的角半径。
import UIKit
@IBDesignable
class CustomRoundedTextField: UITextField {
@IBInspectable var lColor: UIColor = UIColor(red: (37.0/255.0), green: (252.0/255), blue: (244.0/255.0), alpha: 1.0)
@IBInspectable var lWidth: CGFloat = 1
@IBInspectable var lCornerRadius: CGFloat = 8
@IBInspectable var sColor:UIColor = UIColor(red: (37.0/255.0), green: (252.0/255), blue: (244.0/255.0), alpha: 1.0)
@IBInspectable var TLRCorner:Bool = false
@IBInspectable var TRRCorner:Bool = false
@IBInspectable var BLRCorner:Bool = false
@IBInspectable var BRRCorner:Bool = false
@IBInspectable var XInset:CGFloat = 10
@IBInspectable var YInset:CGFloat = 10
required internal init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
override internal func drawRect(rect: CGRect) {
addBorderFieldRect()
}
override func textRectForBounds(bounds: CGRect) -> CGRect {
return CGRectInset(bounds, XInset, 0)
}
override func editingRectForBounds(bounds: CGRect) -> CGRect {
return CGRectInset(bounds, YInset, 0)
}
func addBorderFieldRect() {
let rectanglePath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [
TLRCorner ? .TopLeft : [],
TRRCorner ? .TopRight : [],
BLRCorner ? .BottomLeft : [],
BRRCorner ? .BottomRight : []
], cornerRadii: CGSizeMake(lCornerRadius, lCornerRadius))
rectanglePath.closePath()
self.lColor.setFill()
rectanglePath.fill()
self.sColor.setStroke()
rectanglePath.lineWidth = lWidth
rectanglePath.stroke()
}
}