我是iOS新手。我正在做一個聊天應用程序。下面的圖片是表格消息。在每一個細胞,我設置4個角落messageView
,並顯示正確的UIBezierPath的角落爲靈活的視圖(視圖可以通過內容增加寬度高度)
self.messageView.layer.cornerRadius = 10.0;
現在,我想我的一些消息只有3角(左上,左下,右下)和一些消息有3個角落(左下角,右下角,右上角) - 像facebook messenger
所以我用戶UIBezierPath
爲每個單元格。
但我的消息不顯示完整的內容。 但是,當我向上/向下滾動時,單元格重新創建並顯示正確。
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.messageView.layer.mask = maskLayer;
我想我的問題是: 當我爲我的self.messageView
設置康納斯通過UIBezierPath
,該self.messageView
沒有完成畫呢。所以self.messageView.bounds
返回錯誤的值。
但我不知道如何解決它。
任何幫助將不勝感激
你試過'sizeToFit'嗎? – schmidt9
@ schmidt9請引導我在哪裏我應該把'sizeToFit'? –
請閱讀https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/sizeToFit – schmidt9