相关疑难解决方法(0)

如何在iPhone上创建圆角UILabel?

是否有内置的方法来创建圆角UILabels?如果答案是否定的,那么如何创建这样的对象呢?

cocoa-touch objective-c rounded-corners uilabel ios

149
推荐指数
11
解决办法
13万
查看次数

UIView的两个角落

不久之前,我发布了一个关于在视图的两个角上进行四舍五入的问题,得到了很好的响应,但是在实现它时遇到了问题.这是我的drawRect:方法:

- (void)drawRect:(CGRect)rect {
    //[super drawRect:rect]; <------Should I uncomment this?
    int radius = 5;
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + rect.size.height - radius, radius, M_PI, M_PI / 2, 1);
    CGContextAddArc(context, rect.origin.x + rect.size.width - radius, rect.origin.y + rect.size.height - radius, radius, M_PI / 2, 0.0f, 1);
    CGContextClosePath(context);
    CGContextClip(context);
}
Run Code Online (Sandbox Code Playgroud)

正在调用该方法,但似乎不会影响视图的结果.有什么想法吗?

iphone objective-c rounded-corners ios

77
推荐指数
7
解决办法
7万
查看次数

如何在iphone上完成透明度的圆角矩形视图?

许多应用程序在运行耗时的操作时会弹出带圆角的透明视图和activityIndi​​cator.

这个舍入是如何完成的,是否可以使用Interface Builder来实现(因为有很多地方我想使用这样的东西)?或者,我应该使用带有圆形rect或可伸缩图像的imageview吗?我需要自己画背景吗?

到目前为止,我已经设法通过在Interface Builder中设置alphaValue来获得具有相似透明度的基本视图,但它没有圆角,并且透明度似乎也适用于所有子视图(我不想要text和activityindicator透明,但即使我在IB中设置alphaValue似乎也被忽略了).

iphone cocoa-touch rounded-corners

39
推荐指数
5
解决办法
3万
查看次数

如何设置cornerRadius只用于UIView的左下角,右下角和左上角?

有没有办法只为UIView的左下角,右下角和左上角设置cornerRadius?

我尝试了下面这个,但最终让视图消失了.下面的代码有什么问题吗?

    UIBezierPath *maskPath;
    maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(20.0, 20.0)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.path = maskPath.CGPath;
    view.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c ipad ios

32
推荐指数
4
解决办法
4万
查看次数

只有两个圆角?

在我的iPad应用程序中,当用户单击按钮时,我希望第二个视图显示在主视图中.新视图将小于第一个视图,并在显示时使背景变暗.我希望新视图的前两个角显示为圆角,但使用cornerRadius将所有圆角设置为圆角.我怎样才能使两个圆角变圆?

iphone objective-c rounded-corners ipad

20
推荐指数
3
解决办法
2万
查看次数

带圆角的UIView:如何正确剪辑子视图?

我创建了一个UIView覆盖的子类,drawRect:并用于AddArcToPoint()绘制圆角.(我不想使用图层的圆角半径属性,因为我需要定义哪些角必须被舍入.)但是我无法解决的问题是:如果我在(0 | 0)添加子视图,它会隐藏我的圆形角落.知道如何解决这个问题吗?我希望它很好地剪辑.

这是绘制圆角矩形的代码.这是Monotouch,但任何开发人员都应该可以阅读.

(你可以在这里找到完整的代码:https://github.com/Krumelur/RoundedRectView)

public override void Draw (RectangleF rect)
        {
            using (var oContext = UIGraphics.GetCurrentContext())
            {
                oContext.SetLineWidth (this.StrokeWidth);
                oContext.SetStrokeColor (this.oStrokeColor.CGColor);
                oContext.SetFillColor (this.oRectColor.CGColor);

                RectangleF oRect = this.Bounds;

                float fRadius = this.CornerRadius;
                float fWidth = oRect.Width;
                float fHeight = oRect.Height;

                // Make sure corner radius isn't larger than half the shorter side.
                if (fRadius > fWidth / 2.0f)
                {
                    fRadius = fWidth / 2.0f;
                }
                if (fRadius > fHeight / …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch quartz-graphics xamarin.ios ios

18
推荐指数
1
解决办法
2万
查看次数

围绕UIView的一些角落并围绕视图的图层边界

我试图围绕UIView的底部两个角落,并且图层的边框也显示为圆形.我目前在做:

UIRectCorners corners = UIRectCornerBottomLeft | UIRectCornerBottomRight;
CGSize radii = CGSizeMake(kThisViewCornerRadius, kThisViewCornerRadius);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:myView.bounds
                                           byRoundingCorners:corners
                                                 cornerRadii:radii];

CAShapeLayer *maskLayer = [CAShapeLayer layer];
[maskLayer setPath:path.CGPath];
myView.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)

这适用于普通视图.然而,myView的一层都有borderColorborderWidth集,因为你从截图中可以看到,该层的边框是没有得到四舍五入:

问题的屏幕截图

我还尝试了子类化UIView并[CAShapeLayer layer]从中返回+[Class layerClass],并将视图的图层设置形状图层,但边框最终位于视图的子视图下方.

是否可以围绕视图的某些角落,围绕视图的图层边框,并将子视图剪切到图层边框下方?

请注意,这不是关于如何围绕某些角落而不是其他角落,而是如何使笔划正确行为.

objective-c calayer ios

15
推荐指数
2
解决办法
7291
查看次数

UIBezierPath不会绘制圆角底角

我正试图为我的观点制作圆角并解决一个奇怪的问题.

我使用以下代码为我的视图制作圆角

bezierPath = [UIBezierPath bezierPathWithRoundedRect:btnView.bounds
                                       byRoundingCorners:UIRectCornerAllCorners
                                             cornerRadii:radius];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = btnView.bounds;
    maskLayer.path = bezierPath.CGPath;
    btnView.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)

问题是,它不适用于底角.如果我UIRectCornerBottomLeft没有使用任何事情,如果我UIRectCornerAllCorners只使用顶角是圆的.

编辑:我不使用layer.cornerRadius因为我只想圆底角.

事实证明,如果我UIViewAutoresizingFlexibleHeight从视图中删除自动调整遮罩,我没有问题.但我想使用autoresizing mask.有可能,如果是的如何?

我已经尝试在设置图层蒙版之前和之后设置autoresizingMask.没运气!

iphone rounded-corners uiview ios uibezierpath

11
推荐指数
2
解决办法
8319
查看次数

向每个单元格添加带有cornerRadius的UILabel时,UITableView会爬行

我正在为表视图中的每个单元格添加一个UILabel.这最初没有问题.当我使用layer.cornerRadius滚动来围绕UILabel的角落时,表格视图停止.

 UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(cell.bounds.origin.x+10 ,5, 30, 30)];
 label1.backgroundColor = ([[managedObject valueForKey:@"color"] hasPrefix:@"FFFFFF"]) ? [UIColor blackColor] : color;
 label1.layer.cornerRadius = 10.0f;
 [cell addSubview:label1];
Run Code Online (Sandbox Code Playgroud)

cornerradius uitableview uilabel ios

8
推荐指数
2
解决办法
4781
查看次数

如何以允许用户选择单元格背景颜色的方式在UITableViewCell上获得圆角?(但不使用GROUPED模式)

有没有办法在UITableViewCell上获得圆角,方式如下:

  1. 允许在运行时用户选择/自定义单元格背景颜色(单元格可能不是全部具有相同的背景颜色)
  2. 不使用UITableView"GROUPED"模式

所以我假设这意味着我不能在这里使用正常的图像方法来获得圆形边缘,因为在这种情况下它不允许上面的要求1

iphone rounded-corners uitableview ios

7
推荐指数
1
解决办法
2万
查看次数