h34*_*4cr 77 cocoa-touch objective-c uibutton ios
iOS App Store有一个蓝色圆形框架按钮,用于购买/下载应用程序.
在我的应用程序中,您可以下载其他内容,我希望有一个类似的按钮,只是因为它看起来很熟悉用户.
如果您不知道,我的意思是:这些按钮,如"3.99美元"

这怎么可能?
Dim*_*ima 199
您可以操作按钮的CALayer来轻松完成此操作.
// assuming you have a UIButton or more generally a UIView called buyButton
buyButton.layer.cornerRadius = 2;
buyButton.layer.borderWidth = 1;
buyButton.layer.borderColor = [UIColor blueColor].CGColor;
// (note - may prefer to use the tintColor of the control)
Run Code Online (Sandbox Code Playgroud)
你可以调整每一个,以获得你想要的颜色和边框效果.
您还必须在要使用CALayers的任何文件中添加导入
#import <QuartzCore/QuartzCore.h>
Run Code Online (Sandbox Code Playgroud)
abb*_*ood 90
如果你是使用故事板进行iOS设计的忠实粉丝,你可以设置角半径(以及dima的答案中提到的其他参数- 虽然不幸的是不是颜色,因为它是CGColor而Apple现在不弹出窗口中的那个选项identity inspector- > user defined runtime attributes在故事板中,如下所示:

奖金:
您所使用的运行时属性UIButton的占位符文本颜色(参见这里),并改变字体UILabel,UITextField和UIButton以及(见这里)
Gid*_*ing 17
对于像UIButton,的标准iOS控件元素UILabel,您应该使用UIView tintColor属性:
buyButton.layer.borderColor = buyButton.tintColor.CGColor;
Run Code Online (Sandbox Code Playgroud)
对于您所描述的简单边框,请使用来自Dima的使用CALAyer的答案.
如果你想要更多,例如带渐变的圆角矩形,那么使用这种方法作为基础:
创建一个自定义视图,绘制一个圆角矩形并将其放在按钮上.使用此处的搜索功能搜索绘制圆角矩形.绘图通过绘制具有定义的半径(角)和4条直线的4个弧来工作.
FTR,这就是你如何使用正确的iOS7圆角制作UIView,每个Alex和Brian.
我很确定CGPathCreateWithRoundedRect 不会给你"新"圆角.你必须使用bezierPathWithRoundedRect作为"新"角.
#import "UIViewWithIOS7RoundedCorners.h"
@implementation UIViewWithIOS7RoundedCorners
-(void)drawRect:(CGRect)rect
{
// for a filled shape...
UIBezierPath* path =
[UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:4];
[[UIColor blueColor] setFill];
[path fill];
// for just a border...
int thickness=2;
UIBezierPath* path =
[UIBezierPath bezierPathWithRoundedRect:
CGRectInset(self.bounds, thickness/2, thickness/2)
cornerRadius: 4];
path.lineWidth = thickness;
[[UIColor blueColor] setStroke];
[path stroke];
}
@end
// ps don't forget to set .backgroundColor=[UIColor clearColor]
// perhaps in initWithCoder/initWithFrame
Run Code Online (Sandbox Code Playgroud)


希望它可以帮助某人
| 归档时间: |
|
| 查看次数: |
66933 次 |
| 最近记录: |