ios - 如何将椭圆形图层绘制到 UITextField

标签 ios objective-c xcode

我需要将椭圆形绘制到我的文本字段,我不知道如何使用图层绘制,如果有人帮我设计这个阴影,

enter image description here

最佳答案

这是 Anton 回答的 Objective-C 翻译,因为问题被标记为 Objective-C 而不是 Swift:

CAShapeLayer *shadowLayer = [[CAShapeLayer alloc] init];
shadowLayer.fillColor = [UIColor lightGrayColor].CGColor;
shadowLayer.lineWidth = 0.0f;
CGSize shadowSize = CGSizeMake(textField.bounds.size.width + 40, 40);
CGRect shawdowBounds = CGRectMake(0, 0, shadowSize.width, shadowSize.height);
shadowLayer.path = [UIBezierPath bezierPathWithOvalInRect:shawdowBounds].CGPath;
shadowLayer.bounds = shawdowBounds;
shadowLayer.position = CGPointMake(CGRectGetMidX(textField.bounds), CGRectGetMaxY(textField.bounds));
[containerView.layer insertSublayer:shadowLayer atIndex0];

关于ios - 如何将椭圆形图层绘制到 UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55629337/

相关文章:

ios - UITableView 中没有搜索栏的过滤选项

objective-c - NSMutableSet 添加对象

ios - 在 IOS 上的 React Native 上找不到 RCTConvert+AirMap.h 文件错误

ios - 在 iOS 游戏中检查 Facebook 请求

iphone - Cocos2d 游戏在替换场景时崩溃(包含代码)

iphone - 应用内购买应用更新

ios - 关于在IOS中创建动态数据表的建议

ios - 在 ios 通用设备上构建失败,但在模拟器上构建正常

ios - 当我尝试从 Jenkins 构建 Xcode 项目时,出现错误 "String index out of range 15"

ios - 为什么在主线程上调用闭包时我的动画会被忽略?