在 UITextView 内占据左角的 UIImageView
UIImageView that takes left corner inside UITextView
如何为左上角带有 UIImageView 的 UITextView 编写 Xcode objective-C 代码,字符串从 UIImageView 旁边开始。
所以UITextView的文字不会填满矩形区域。
我考虑过制作一个包含 UIImageView 的 UITextView 的子类。但是,我坚持不应该跨越 UIImageView 区域的文本定位。
提前致谢。
试试这个
myTextField.leftViewMode = UITextFieldViewModeAlways;
myTextField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"downArrow.png"]];
希望对您有所帮助。
老兄,试试吧...
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
}
希望下面的链接可以帮助您实现您想要的。
1) [类 扩展了 UILabel、UIButton、UITextField 和 UITextView 的能力]
https://github.com/Friend-LGA/LGViews
2) 更强大的UITextView。
https://github.com/fsjack/JKRichTextView
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 = LeftSide 的 edgeInset
如何为左上角带有 UIImageView 的 UITextView 编写 Xcode objective-C 代码,字符串从 UIImageView 旁边开始。
所以UITextView的文字不会填满矩形区域。 我考虑过制作一个包含 UIImageView 的 UITextView 的子类。但是,我坚持不应该跨越 UIImageView 区域的文本定位。
提前致谢。
试试这个
myTextField.leftViewMode = UITextFieldViewModeAlways;
myTextField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"downArrow.png"]];
希望对您有所帮助。
老兄,试试吧...
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
}
希望下面的链接可以帮助您实现您想要的。
1) [类 扩展了 UILabel、UIButton、UITextField 和 UITextView 的能力] https://github.com/Friend-LGA/LGViews
2) 更强大的UITextView。 https://github.com/fsjack/JKRichTextView
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 = LeftSide 的 edgeInset