【问题标题】:how can I set Specific corner radious in ios?如何在 ios 中设置特定的角半径?
【发布时间】:2017-07-12 12:09:44
【问题描述】:

如何设置特定的圆角半径?我在单元格中添加了标签。标签是多行。

我尝试了以下代码,但问题是高度没有增加。

+ (UIView *)roundCornersOnView:(UIView *)view onTopLeft:(BOOL)tl topRight:(BOOL)tr bottomLeft:(BOOL)bl bottomRight:(BOOL)br radius:(float)radius
{
    if (tl || tr || bl || br) {
        UIRectCorner corner = 0;
        if (tl) corner = corner | UIRectCornerTopLeft;
        if (tr) corner = corner | UIRectCornerTopRight;
        if (bl) corner = corner | UIRectCornerBottomLeft;
        if (br) corner = corner | UIRectCornerBottomRight;

        UIView *roundedView = view;
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:roundedView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        maskLayer.frame = roundedView.bounds;
        maskLayer.path = maskPath.CGPath;
        roundedView.layer.mask = maskLayer;
        return roundedView;
    }
    return view;
}


 // In cellforRow code like following
    [CommonUtils roundCornersOnView:cell.senderView onTopLeft:YES topRight:YES bottomLeft:YES bottomRight:NO radius:cell.senderView.frame.size.height / 2];

当我使用普通代码时,它的工作和高度增加。

cell.label.layer.cornerRadius = cell.label.frame.size.height/2;

请帮我解决这个问题。

【问题讨论】:

  • 你的意思是Label的高度没有增加??
  • 当我使用上层代码时,高度增加但标签没有增加。意味着尝试转角半径
  • 好的。所以在设置正常圆角半径cell.label.layer.cornerRadius = cell.label.frame.size.height/2;时它的工作方式???
  • 是的.......它工作
  • 不添加单独的UIView,,,你只需添加UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:roundedView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = roundedView.bounds; maskLayer.path = maskPath.CGPath; cell.label.layer.mask = maskLayer;

标签: ios objective-c iphone


【解决方案1】:

您必须为此使用图像,就像所有聊天应用程序和信使应用程序一样。 但是您必须为图像设置一些条件,以便来自发送方或接收方的继续消息相应地设置单元格的背景图像。

你可以检查 https://github.com/jessesquires/JSQMessagesViewController

【讨论】:

  • 你能解释一下吗
【解决方案2】:

我试过这段代码是可以工作的,你可以创建一个单独的 UIView 区域测试

至于为什么你的手机不工作,我觉得是其他原因

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多