ios - TextField 圆角半径 : Not Sharp Corners

标签 ios swift uitextfield uikit calayer

我正在尝试在适用于 uitextfield 效果但不适用尖角的情况下添加圆角半径。

请检查所附图片。 enter image description here

我期待这样的结果。 enter image description here

这是我的灰色文本字段代码。

 self.layer.cornerRadius = 7.5
 self.layer.borderWidth = 1.5
 self.layer.borderColor =  UIColor(red: 209/255.0, green: 209/255.0, blue: 209/255.0, alpha: 1.0).CGColor 
 self.backgroundColor = UIColor.whiteColor() 

这是我的红色文本字段代码。

 self.layer.cornerRadius = 7.5
 self.layer.borderWidth = 1.5
 self.layer.borderColor = TextFieldRedBorderColor.CGColor
 self.backgroundColor = TextFieldRedBackgroundColor 

两个代码之间只有颜色差异,但仍然无法正常工作。

最佳答案

self.layer.masksToBounds = true

这将解决您的问题

关于ios - TextField 圆角半径 : Not Sharp Corners,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40316231/

相关文章:

ios - 如何从 AVCaptureVideoPreviewLayer 获取 UIImage?

ios - ICViewPager 顶部和底部有奇怪的空格

ios - UICollectionView:有没有办法只重新加载补充 View ?

ios - 如何使用 UIWebView 制作浏览器?

ios - 如果文本为空,UITableViewCell detailTextLabel 不支持 KVO?苹果漏洞?

ios - 在 AppStore 上传 iOS 应用程序

ios - 更改 UISwitch 图像

string - Swift - 用空格替换字符串中的表情符号

ios - 在 Swift 中将分数从 UITextField 转换为小数

ios - 如何调整 UITextField 占位符文本大小以适合 UITextField 宽度?