Reputation: 129
How can I write Xcode objective-C code for UITextView with UIImageView on top left corner and string starts right next to UIImageView.
So UITextView text will not fill out the rectangle area. I thought about making a subclass of UITextView that contains UIImageView. But then, i am stuck with text positioning that should not cross the UIImageView area.
Thanks in advance.
Upvotes: 0
Views: 1331
Reputation: 1192
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(100, 150, 100, 60)];
[textView setTextContainerInset:UIEdgeInsetsMake(0, 30, 0, 0)];//30**
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 60)];//30**
[imageView setImage:[UIImage imageNamed:@"imageName"]];
[textView addSubview:imageView];
[self.view addSubview:textView];
30** = imageWidth = edgeInset for LeftSide
Upvotes: 3
Reputation: 1964
Hope Below Links may help you achieve what you want.
1) [Classes extends abilities of UILabel, UIButton, UITextField and UITextView] https://github.com/Friend-LGA/LGViews
2) A more powerful UITextView. https://github.com/fsjack/JKRichTextView
Upvotes: 1
Reputation: 1199
Try it dude...
func addButtonInTextField(image:UIImage, forTextField text:UITextField) ->UIButton{
let kImageEdge:CGFloat = 2.0
let ysFix_button = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
ysFix_button.frame = CGRectMake(text.frame.origin.x, text.frame.origin.y, text.frame.size.width / 7, text.frame.size.height)
ysFix_button.imageEdgeInsets = UIEdgeInsetsMake(kImageEdge,kImageEdge,kImageEdge,kImageEdge)
ysFix_button.setImage(image, forState: UIControlState.Normal)
text.rightView = ysFix_button
text.rightViewMode = UITextFieldViewMode.Always
return ysFix_button
}
Upvotes: 2
Reputation: 2220
Try this
myTextField.leftViewMode = UITextFieldViewModeAlways;
myTextField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"downArrow.png"]];
Hope it helps.
Upvotes: 2