设置内容为插图作为UITextView的如何我有一个UITextView并将内容插入IOS
[atextView setContentInset:UIEdgeInsetsMake(0, 10, 0, 0)];
此代码的iOS 6.1及以下的工作,但没有任何反应iOS中7.0。
设置内容为插图作为UITextView的如何我有一个UITextView并将内容插入IOS
[atextView setContentInset:UIEdgeInsetsMake(0, 10, 0, 0)];
此代码的iOS 6.1及以下的工作,但没有任何反应iOS中7.0。
得到了回答:
[atextView setTextContainerInset:UIEdgeInsetsMake(7, 7, 0, 0)];
固定我的问题。
而且在斯威夫特...
@IBOutlet var tv:UITextView!
override func awakeFromNib()
{
super.awakeFromNib()
tv.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0);
}
UPDATE:另一种选择这样做。
UIView *spacerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
[msgtext setLeftViewMode:UITextFieldViewModeAlways];
[msgtext setLeftView:spacerView];
另一种也许有点更便捷的方式来做到这一点,通过继承的UITextField并添加@IBInspectable插图性质。
import UIKit
class UITextfieldWithInset: UITextField {
@IBInspectable
var textfieldInset: CGPoint = CGPointMake(0, 0)
override func textRectForBounds(bounds: CGRect) -> CGRect {
return CGRectInset(bounds, textfieldInset.x, textfieldInset.y)
}
override func editingRectForBounds(bounds: CGRect) -> CGRect {
return CGRectInset(bounds, textfieldInset.x, textfieldInset.y)
}
override func placeholderRectForBounds(bounds: CGRect) -> CGRect {
return CGRectInset(bounds, textfieldInset.x, textfieldInset.y)
}
}
这是'UITextField'的一个很好的答案,但问题是'UITextView' – dulgan
有没有办法做到这一点**在故事板**?! – Fattie
你试过更新的答案了吗? –
是的,请查看下面的解决方案Joe Blow –