当然,我在这里看到很多 Core Graphics 问题,所以如果这是一个骗局,请将我转到现有答案。
在 ScrollView 中,我有一些标签和文本字段。文本字段有边框。
我似乎想不通的是如何在边框和文本之间添加填充。
您可以在这张图片中看到发生了什么:
这是执行此操作的代码片段:
roughDate = [[UITextField alloc] init] ;
CGRect tempFrame = CGRectMake(125, 90, 300, 40);
UIEdgeInsets insets = UIEdgeInsetsMake(4, 4, 4, 4);
CGRect roughDateFrame = UIEdgeInsetsInsetRect(tempFrame, insets);
NSLog(@"%@", NSStringFromCGRect(roughDateFrame));
[[roughDate layer] setBorderColor:[[UIColor grayColor] CGColor]];
[[roughDate layer] setBorderWidth:1.0];
[[roughDate layer] setCornerRadius:5];
roughDate.frame = roughDateFrame;
[subview addSubview:roughDate];
最佳答案
使用这个:
_textField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
_textField.leftViewMode = UITextFieldViewModeAlways;
_textField.background = [[UIImage imageNamed:@"image"] stretchableImageWithLeftCapWidth:7 topCapHeight:17];
关于ios - 如何为 UITextField 制作边框填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18225791/