复写UITextField,UIButton,UILabel的方法 UITextField的方法
- (CGRect)textRectForBounds:(CGRect)bounds { CGRect inset = CGRectMake(bounds.origin.x + 40, bounds.origin.y, bounds.size.width -40, bounds.size.height); return inset; } - (CGRect)editingRectForBounds:(CGRect)bounds { // return CGRectInset( bounds , 40 , 0 ); CGRect inset = CGRectMake(bounds.origin.x + 40, bounds.origin.y, bounds.size.width -40, bounds.size.height); return inset; } - (CGRect)leftViewRectForBounds:(CGRect)bounds { CGRect inset = CGRectMake(bounds.origin.x +10, bounds.origin.y + 7, 25, 25); return inset; } UILabel的方法 (字体加白色阴影) - (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset; UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(c, 1); CGContextSetLineJoin(c, kCGLineJoinRound);
CGContextSetTextDrawingMode(c, kCGTextStroke); self.textColor = [UIColor whiteColor]; [super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill); self.textColor = textColor; self.shadowOffset = CGSizeMake(0, 0); [super drawTextInRect:rect]; self.shadowOffset = shadowOffset;
} UIButton和UITextField类似 |
|