如何设置ios中的特定角落?

时间:2017-07-12 12:09:44

标签: ios objective-c iphone

如何设置特定的角落?我在cell.label中添加了标签是Multiline。

我尝试过以下代码,但问题是高度不会增加。

+ (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;

imapliment

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:0)

你必须使用图像,因为所有聊天应用程序和信使应用程序都可以。 但是你必须为图像制作一些条件,以便发送者或接收者的继续消息相应地为单元格设置背景图像。

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

答案 1 :(得分:0)

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

至于为什么你的细胞不起作用,我认为这是出于其他原因

相关问题