[Tips] UITextview를 UILabel처럼 사용
10564 단어 iOSUIKitSwiftUILabelUITextView
개요
UITextview를 UILabel처럼 사용하기위한 Tips. 덧붙여 IBDesignable 입문 로부터의 추출 정보.
할 일
@IBDesignbable
를 부가. Padding
를 0으로 지정. Scrolling Enabled
를 false로 지정. 코드
IBDesinable 용 UITextView 상속 클래스@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "UITextView")
@IBDesignable final class DesignableTextView: UITextView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
}
}
UITextViewExtensionextension UITextView {
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.top")
@IBInspectable var topPadding: Float {
get { return Float(self.textContainerInset.top) }
set { textContainerInset.top = CGFloat(newValue) }
}
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.left")
@IBInspectable var leftPadding: Float {
get { return Float(self.textContainerInset.left + 5) }
set { textContainerInset.left = CGFloat(newValue - 5) }
}
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.right")
@IBInspectable var rightPadding: Float {
get { return Float(self.textContainerInset.right + 5) }
set { textContainerInset.right = CGFloat(newValue - 5) }
}
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.bottom")
@IBInspectable var bottomPadding: Float {
get { return -1 * Float(self.textContainerInset.bottom) }
set { textContainerInset.bottom = -1 * CGFloat(newValue) }
}
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainer.maximumNumberOfLines")
@IBInspectable var lines: Int {
get { return textContainer.maximumNumberOfLines }
set { textContainer.maximumNumberOfLines = newValue }
}
}
비고
(특히 없음)
Reference
이 문제에 관하여([Tips] UITextview를 UILabel처럼 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ShoichiKuraoka/items/5b4c40936e1467406878
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "UITextView")
@IBDesignable final class DesignableTextView: UITextView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
}
}
extension UITextView {
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.top")
@IBInspectable var topPadding: Float {
get { return Float(self.textContainerInset.top) }
set { textContainerInset.top = CGFloat(newValue) }
}
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.left")
@IBInspectable var leftPadding: Float {
get { return Float(self.textContainerInset.left + 5) }
set { textContainerInset.left = CGFloat(newValue - 5) }
}
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.right")
@IBInspectable var rightPadding: Float {
get { return Float(self.textContainerInset.right + 5) }
set { textContainerInset.right = CGFloat(newValue - 5) }
}
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainerInset.bottom")
@IBInspectable var bottomPadding: Float {
get { return -1 * Float(self.textContainerInset.bottom) }
set { textContainerInset.bottom = -1 * CGFloat(newValue) }
}
@available(*, unavailable, message: "Only use it at Storybord or Xib. When referring it from their file to Swift file, replace reference class name to inherited class.", renamed: "textContainer.maximumNumberOfLines")
@IBInspectable var lines: Int {
get { return textContainer.maximumNumberOfLines }
set { textContainer.maximumNumberOfLines = newValue }
}
}
(특히 없음)
Reference
이 문제에 관하여([Tips] UITextview를 UILabel처럼 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ShoichiKuraoka/items/5b4c40936e1467406878텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)