分享

UITextField,UILabel的复写方法

 skylonely 2014-05-17
                  复写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类似

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多