I see many Core Graphics questions here of course, so if this is a dupe, please forward me to the existing answer.
Inside a scroll view, I have some labels and textfields. The text fields have borders.
What I can't seem to figure out is how to make a padding between the border and the text.
You can see what's happening in this image:
This is the code snippet that's doing this:
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];
Use This:
_textField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
_textField.leftViewMode = UITextFieldViewModeAlways;
_textField.background = [[UIImage imageNamed:@"image"] stretchableImageWithLeftCapWidth:7 topCapHeight:17];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.