有没有办法cornerRadius只设置一个左上角和右上角UIView?
我尝试了以下内容,但最终没有看到视图了.
UIView *view = [[UIView alloc] initWithFrame:frame];
CALayer *layer = [CALayer layer];
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:frame byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(3.0, 3.0)];
layer.shadowPath = shadowPath.CGPath;
view.layer.mask = layer;
Run Code Online (Sandbox Code Playgroud) 我目前正在寻找具有属性的UILabel addMessageLabel.layer.cornerRadius = 5.0f;在安装了iOS 7.0的设备上,它有圆角.在安装了iOS 7.1的设备上,它没有圆角.
这只是iOS 7.1的一个错误吗?
我正在尝试创建一个带圆角和投影的按钮.无论我如何切换,按钮都无法正确显示.我试过masksToBounds = false和masksToBounds = true,但无论是圆角半径工程和影子不或影子工程和圆角半径不夹按钮的角落.
import UIKit
import QuartzCore
@IBDesignable
class Button : UIButton
{
@IBInspectable var masksToBounds: Bool = false {didSet{updateLayerProperties()}}
@IBInspectable var cornerRadius : CGFloat = 0 {didSet{updateLayerProperties()}}
@IBInspectable var borderWidth : CGFloat = 0 {didSet{updateLayerProperties()}}
@IBInspectable var borderColor : UIColor = UIColor.clearColor() {didSet{updateLayerProperties()}}
@IBInspectable var shadowColor : UIColor = UIColor.clearColor() {didSet{updateLayerProperties()}}
@IBInspectable var shadowOpacity: CGFloat = 0 {didSet{updateLayerProperties()}}
@IBInspectable var shadowRadius : CGFloat = 0 {didSet{updateLayerProperties()}}
@IBInspectable var shadowOffset …Run Code Online (Sandbox Code Playgroud) 我试图动画的变化cornerRadius一个的UIView实例layer,但的变化cornerRadius立即生效.
这是代码:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
view.layer.masksToBounds = YES;
view.layer.cornerRadius = 10.0;
[UIView animateWithDuration:1.0 animations:^{
[view.layer.cornerRadius = 0.0;
}];
Run Code Online (Sandbox Code Playgroud)
谢谢大家给我任何提示.
编辑:我设法Core Animation使用a 来动画这个属性CABasicAnimation.
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSNumber numberWithFloat:10.0f];
animation.toValue = [NSNumber numberWithFloat:0.0f];
animation.duration = 1.0;
[viewToAnimate.layer addAnimation:animation forKey:@"cornerRadius"];
[animation.layer setCornerRadius:0.0];
Run Code Online (Sandbox Code Playgroud) 在Objective-C这样的行
self.mainImageView.layer.cornerRadius = CGRectGetWidth(self.mainImageView.frame)/4.0f;
Run Code Online (Sandbox Code Playgroud)
做它的工作,我在Swift中尝试使用类比
self.mainImageView.layer.cornerRadius = CGRectGetWidth(self.mainImageView.frame)/4.0
Run Code Online (Sandbox Code Playgroud)
并且它不会改变任何东西,角落和以前一样.而且,Xcode没有显示任何语法错误.Swift是否支持任何其他方式来实现这一目标?我在这里检查了一些其他线程,通常它是以上面显示的方式在Swift中完成的.
我试图设置UIButton的cornerRadius,但我不知道该怎么做.
如果我喜欢这样:
button.layer.cornerRadius = 5;
Run Code Online (Sandbox Code Playgroud)
效果很好,如果我这样做:
button.layer.cornerRadius = 5;
[button setBackgroundColor:[UIColor colorWithPatternImage:radialGradient]];
Run Code Online (Sandbox Code Playgroud)
角落不圆.
我知道我可以解决这个问题
[button.layer setMasksToBounds:YES];
Run Code Online (Sandbox Code Playgroud)
但我特意寻找不同的解决方案,因为我在按钮上添加了一些箭头,如果我将蒙版设置为边界,则箭头会被遮盖.
编辑:
radialGradient是whit func
+ (UIImage *)getRadialGradientImage:(CGSize)size centre:(CGPoint)centre radius:(float)radius startColor:(UIColor *)startColor endColor:(UIColor *)endColor{
// Initialise
UIGraphicsBeginImageContextWithOptions(size, YES, 1);
// Create the gradient's colours
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
const CGFloat *component_first = CGColorGetComponents([startColor CGColor]);
CGFloat red1 = component_first[0];
CGFloat green1 = component_first[1];
CGFloat blue1 = component_first[2];
const CGFloat *component_second = CGColorGetComponents([endColor CGColor]);
CGFloat red2 = component_second[0];
CGFloat green2 …Run Code Online (Sandbox Code Playgroud) 我在 swiftUI 中有一个文本字段,为了使其更具吸引力,我想添加边框并具有圆角。但它似乎并没有像预期的那样工作(见图)。我错过了什么?

我尝试将 .cornerradius() 放在 .border() 之前,但它具有相同的效果。
TextField("Text input goes here", text: $addMins)
.padding(.all, 5.0)
.background(View)
.frame(width: 300.0, height: 35.0)
.border(Color.green, width: 2)
.cornerRadius(14)
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以在UIVisualEffectView上设置角半径?这是我尝试过的代码:
@IBOutlet var blurView: UIVisualEffectView!
var blurLayer : CALayer{
return blurView.layer
}
override func viewDidLoad() {
super.viewDidLoad()
setUpLayer()
// Do any additional setup after loading the view.
}
func setUpLayer(){
blurLayer.cornerRadius = 50
}
Run Code Online (Sandbox Code Playgroud)
和
@IBOutlet var blurView: UIVisualEffectView!
override func viewDidLoad() {
super.viewDidLoad()
blurView.layer.cornerRadius = 50
// Do any additional setup after loading the view.
}
Run Code Online (Sandbox Code Playgroud)
不是他们的作品.
我正试图在android上制作循环进度条,这看起来非常简单,但我正在努力完成进度和次要进度的边缘.
有没有办法在不制作自定义视图的情况下做到这一点?使用角半径?还是九个补丁?
对于这个视图(参见附件)我使用的是一个简单的xml文件
<item android:id="@android:id/progress">
<shape
android:useLevel="true"
android:innerRadius="@dimen/sixty_dp"
android:shape="ring"
android:thickness="@dimen/seven_dp">
<solid android:color="#477C5B"/>
<stroke android:width="1dip"
android:color="#FFFF"/>
</shape>
</item>
Run Code Online (Sandbox Code Playgroud)

我想用子类修改UISegmentedControl来删除圆角.我似乎无法设置cornerRadius.使SegmentedControl比屏幕更宽(因此从角落"切掉")不是一种选择,因为我有4或5个段,然后它们的大小会有所不同.
有没有办法做到这一点?
谢谢
cornerradius ×10
ios ×6
swift ×4
uiview ×3
xcode6 ×2
android ×1
border ×1
cocoa-touch ×1
drawable ×1
ios5 ×1
ios7 ×1
progress-bar ×1
shadow ×1
swiftui ×1
textfield ×1
uibutton ×1
uiimageview ×1
uilabel ×1
widget ×1