4
UITextView
에 textview.selectable = true
이 있고 UIButton
을 사용하여 선택한 TextColor를 변경하려면 어떻게해야합니까?UITextView 선택한 텍스트의 색
UITextView
에 textview.selectable = true
이 있고 UIButton
을 사용하여 선택한 TextColor를 변경하려면 어떻게해야합니까?UITextView 선택한 텍스트의 색
문자열의 선택한 범위를 변경하려면 attributedText
속성을 변경해야합니다.
@IBAction func didTapButton(sender: UIButton) {
let range = textView.selectedRange
let string = NSMutableAttributedString(attributedString: textView.attributedText)
let attributes = [NSForegroundColorAttributeName: UIColor.redColor()]
string.addAttributes(attributes, range: textView.selectedRange)
textView.attributedText = string
textView.selectedRange = range
}
전체 문자열을 변경하려면 CeceXX에서 제안한 기술을 사용할 수 있습니다.
@IBAction func didTapButton(sender: UIButton) {
textView.textColor = UIColor.redColor()
}
수정 사항을 찾았습니까? 그렇다면 정답을 게시하십시오. – Cesare