These methods just allow you to add a rect (frame) to your textfield's label. newBounds method create the rect (frame) that will be added to textfield's label. Finally your padding is: let padding = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5);
We can add padding to a JTextField using the setMargin(Insets s) of JTextComponent class.
You can Change the Hyperlink Color in a TextView by the following: In the Nib file, you can go to the Properties Window and change the Tint to which ever color you want to.
Starting from iOS 7 you can use textContainerInset
property:
Objective-C
textView.textContainerInset = UIEdgeInsetsMake(0, 20, 0, 20);
Swift
textView.textContainerInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
After fiddling around with this for a while I found another solution if you're only developing for iOS 6. Set the top and bottom margins with contentInset:
textView = [[UITextView alloc] init];
textView.contentInset = UIEdgeInsetsMake(20.0, 0.0, 20.0, 0.0);
For the left and right margins don't add your plain text right away but use an NSAttributedString instead with properly set left and right indents with an NSMutableParagraphStyle:
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.headIndent = 20.0;
paragraphStyle.firstLineHeadIndent = 20.0;
paragraphStyle.tailIndent = -20.0;
NSDictionary *attrsDictionary = @{NSFontAttributeName: [UIFont fontWithName:@"TrebuchetMS" size:12.0], NSParagraphStyleAttributeName: paragraphStyle};
textView.attributedText = [[NSAttributedString alloc] initWithString:myText attributes:attrsDictionary];
This gives you a UITextView with your text (in my case from the variable myText) with 20 pixels padding that properly scrolls.
Try this
UIBezierPath* aObjBezierPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 20, 20)];
txtView.textContainer.exclusionPaths = @[aObjBezierPath];
You could just use a smaller UITextView, and place a UIView in the background to simulate the padding.
+----------+
| | <-- UIView (as background)
| +--+ |
| | | <---- UITextView
| | | |
| +--+ |
| |
+----------+
if you want to set padding from one side, you can use below code:
textView.contentInset.left = 5 //For left padding
textView.contentInset.right = 5 //For right padding
textView.contentInset.top = 5 //For top padding
textView.contentInset.bottom = 5 //For bottom padding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With