Setting masked corners in Interface Builder

2019-04-28 17:44发布

What type of value is [.layerMaxXMinYCorner, .layerMinXMinYCorner]? Is it possible to set this parameter on a View in Interface Builder? I know how to set layer.borderWidth, layer.borderUIColor and layer.cornerRadius in the Identity Inspector, but I can't figure out the right Type and Value to use for masked corners.

Thanks!

Jake


Update: here are the integer values for each combination (in terms of which are rounded):

  • 0: no rounded corners
  • 1: top left
  • 2: top right
  • 3: top left & right (both top corners)
  • 4: bottom left
  • 5: top & bottom left (both left corners)
  • 6: top right & bottom left
  • 7: top left & right, bottom left (all corners except bottom right)
  • 8: bottom right
  • 9: top left, bottom right
  • 10: top & bottom right (both right corners)
  • 11: both top corners, bottom right (all corners except bottom left)
  • 12: bottom left & right (both bottom corners)
  • 13: bottom left & right, top left (all corners except top right)
  • 14: bottom left & right, top right (all corners except top left)
  • 15: all corners rounded

  • Top left is in 1, 3, 5, 7, 9, 11, 13, 15
  • Top right is in 2-3, 6-7, 10-11, 14-15
  • Bottom left is in 4-7, 12-15
  • Bottom right is in 8-15

  • Both top corners are in 3, 7, 11, 15

  • Both right corners are in 10-11, 14,15
  • Both bottom corners are in 12-15
  • Both left corners are in 5, 7, 13, 15

1条回答
叛逆
2楼-- · 2019-04-28 18:04

maskedCorners is a CACornerMask, which is an OptionSet, or bit mask. The raw value is an integer: in code, you can try printing the value of someView.layer.maskedCorners.rawValue, or setting it via someView.layer.maskedCorners.setValue(3, forKey: "maskedCorners").

So you should be able to set the value of layer.maskedCorners to the integer 3 (or whatever you need) in Interface Builder, and I don't see why it would be unsafe to do this. Though it will be a pain to figure out what set of corners that integer value actually maps to if you forget.

查看更多
登录 后发表回答