ios - 左右边的圆角不正确

标签 ios swift rounded-corners

我正在工作或项目中,我必须给角落从左上角和右上角查看。我正在为此使用自动布局。我的 View 宽度是 296。这是设计

first cell

根据我在 tableview 第一个单元格中的设计,我的代码到 selected view

的圆角
            let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath)
            let  view_  = cell.viewWithTag(10)! as UIView
 let maskLayer : CAShapeLayer = CAShapeLayer()
            let maskpath = UIBezierPath(roundedRect: view_.bounds, byRoundingCorners: [.TopLeft,.TopRight], cornerRadii: CGSizeMake(10, 10))
            
            maskLayer.frame = view_.bounds;
            maskLayer.path = maskpath.CGPath;
            
            view_.layer.mask = maskLayer
            cell.selectionStyle = UITableViewCellSelectionStyle.None
            return cell

但我的问题是我得到了这个输出

enter image description here

我给 view_.bounds 但我不知道为什么它采用该 View 的原始帧值。在像 iphone 4s 和 5 这样的小型设备中,它可以完美地提供输出,但在大型设备中它会出现问题,如屏幕截图。

请帮帮我

最佳答案

问题是您运行代码的时间太早了。您的代码取决于我们知道 view_.bounds 的假设:

let maskpath = UIBezierPath(roundedRect: view_.bounds, byRoundingCorners: [.TopLeft,.TopRight], cornerRadii: CGSizeMake(10, 10))
maskLayer.frame = view_.bounds;

但在您的代码运行时,该值尚未最终确定。这里要记住的是, View 在放入界面时会调整大小。您希望将代码推迟到view_.bounds 达到其最终值(也称为布局)。

关于ios - 左右边的圆角不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40602685/

相关文章:

ios - 我有一个对象,需要访问它的一个组件

ios - 在 CollectionView 上滑动删除

java - 使所有 JButton 都带有圆角的最佳方法

WPF GridView 标题不会水平滚动

ios - 如何制作一个圆形的椭圆形按钮?

ios - 如何制作这个动画?即。连接共享元素

ios - 如何让 titleView 在推送/弹出转换期间保留在 UINavigationBar 中,如 Facebook 应用程序?

ios - 在 Xcode 5.1.1 中打开 Storyboard后屏幕变黑

ios - 更改 UIImagePickerController 的 TintColor

ios - 使用图像缓存时展开 [String] 的问题