[英]How to create Badges like Foursquare did?
这可能不是世界上最好的代码,但它应该可以工作。 您必须导入 QuartzCore/QuartzCore.h,并且不要忘记将按钮添加为子视图。
UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 15)];
[btn setTitle:@“Hello” forState:UIControlStateNormal];
[btn sizeToFit];
CGRect frame = btn.frame;
// adding horizontal spacing
frame = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame), CGRectGetWidth(frame) + 24, CGRectGetHeight(frame));
// decreasing vertical spacing
frame = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame), CGRectGetWidth(frame), CGRectGetHeight(frame) - 8);
btn.frame = frame;
btn.layer.cornerRadius = CGRectGetHeight(frame)/2;
btn.clipsToBounds = YES; // not sure if needed
// if you want a border:
btn.layer.borderWidth = 1;
btn.layer.borderColor = [UIColor greenColor].CGColor;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.