nelm
nelm

Reputation: 129

UIImageView that takes left corner inside UITextView

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

Answers (4)

Shebin Koshy
Shebin Koshy

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

Niraj
Niraj

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

Sankalap Yaduraj Singh
Sankalap Yaduraj Singh

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

Pradumna Patil
Pradumna Patil

Reputation: 2220

Try this

   myTextField.leftViewMode = UITextFieldViewModeAlways;
    myTextField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"downArrow.png"]];

Hope it helps.

Upvotes: 2

Related Questions