uitextview

iOS - How to predefine TextView line height

南楼画角 提交于 2021-02-18 19:40:39
问题 I've some UITextView declared as the following lazy var inputTextView: UITextView = { let tv = UITextView() tv.tintColor = UIColor.darkGray tv.font = UIFont.systemFont(ofSize: 17) tv.backgroundColor = UIColor.white return tv }() I've been searching how can I predefine the line height for this UITextView so whenever I write a long text, when it reaches the end of the line and goes to the following line, the spacing would be bigger than the default. I've tried using the following inside the

Strange crash in UITextview undo on iOS 7

浪尽此生 提交于 2021-02-18 11:13:32
问题 I have been receiving a bunch of crash reports that look a lot like the following with different values for the range. Sometimes the range is not 0-x it could be say 2-x Application Specific Information: * Terminating app due to uncaught exception \'NSRangeException\',reason: \'* -[NSBigMutableString substringWithRange:]: Range {0, 69} out of bounds; string length 0\' Last Exception Backtrace: 0 CoreFoundation 0x2e879e83 __exceptionPreprocess + 131 1 libobjc.A.dylib 0x38bd66c7 objc_exception

Resize the UITextView when keyboard appears

时光毁灭记忆、已成空白 提交于 2021-02-18 06:37:12
问题 I want to resize the text view when the keyboard appears. The code I have is below. I have auto layout on, hence using a constraint of textView->bottom space from superview and referencing it via IBOutlet distanceFromBottom. - (void)keyboardWillShow:(NSNotification *)notification { [UIView animateWithDuration:0.3 animations:^{ NSDictionary* d = [notification userInfo]; CGRect r = [d[UIKeyboardFrameEndUserInfoKey] CGRectValue]; r = [textView convertRect:r fromView:Nil]; if(IS_IPHONE_6||IS

UITextView - adjust size based on the content in SwiftUI

£可爱£侵袭症+ 提交于 2021-02-14 18:18:32
问题 I am trying to figure out how to make UITextView size dependent on it's contents in SwiftUI. I wrapped the UITextView in UIViewRepresentable as following: struct TextView: UIViewRepresentable { @Binding var showActionSheet: Bool func makeCoordinator() -> Coordinator { Coordinator(self) } func makeUIView(context: Context) -> UITextView { let uiTextView = UITextView() uiTextView.delegate = context.coordinator uiTextView.font = UIFont(name: "HelveticaNeue", size: 15) uiTextView.isScrollEnabled =

How to calculate UITextView first baseline position relatively to the origin

家住魔仙堡 提交于 2021-02-11 15:23:31
问题 How can I calculate UITextView first baseline position? I tried calculating it this way: self.textView.font!.descender + self.textView.font!.leading However, the value I'm getting is not correct. Any ideas, hints? 回答1: Based on the documentation zcui93 gives, font.ascender will give you the offset to the baseline within the font. To get the baseline of the font within the UITextView you need to add in textContainerInset.top : extension UITextView { func firstBaseline() -> CGFloat { let font =

swift uitextview html image causes crash when copy image is selected after long press

两盒软妹~` 提交于 2021-02-11 12:32:22
问题 I currently have a UITextView that is displaying an NSAttributedString that contains HTML data with text and images. This data is received via API so images and text are all combined into one HTML string. This is the function that parses the HTML. let htmlData = NSString(string: myString).data(using: String.Encoding.unicode.rawValue); let options = [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html]; do{ let text = try NSMutableAttributedString

Force UITextView cursor to the top of the view

非 Y 不嫁゛ 提交于 2021-02-11 05:35:30
问题 I have a UITableView that contains a series of text input fields, which can be UITextField or UITextView controls. When a text input field is selected, the keyboard's 'Next' button is used to cycle through the fields. This all works properly except for one thing. When a UITextView (multiline) receives focus by calling becomeFirstResponder, the cursor is positioned at the second line in the view, not the first. This seems to be the most common suggestion to address the issue, but it does not

Force UITextView cursor to the top of the view

烂漫一生 提交于 2021-02-11 05:33:27
问题 I have a UITableView that contains a series of text input fields, which can be UITextField or UITextView controls. When a text input field is selected, the keyboard's 'Next' button is used to cycle through the fields. This all works properly except for one thing. When a UITextView (multiline) receives focus by calling becomeFirstResponder, the cursor is positioned at the second line in the view, not the first. This seems to be the most common suggestion to address the issue, but it does not

Force UITextView cursor to the top of the view

若如初见. 提交于 2021-02-11 05:33:14
问题 I have a UITableView that contains a series of text input fields, which can be UITextField or UITextView controls. When a text input field is selected, the keyboard's 'Next' button is used to cycle through the fields. This all works properly except for one thing. When a UITextView (multiline) receives focus by calling becomeFirstResponder, the cursor is positioned at the second line in the view, not the first. This seems to be the most common suggestion to address the issue, but it does not

Swift: Scroll a UITextView horizontally

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-10 09:37:32
问题 I want to display selected contacts on a label which could be scrolled like in Snapchat. After going through lot of questions on stackoverflow I have used Textview since it is scrollable. @IBOutlet weak var selectedContactsDisplay: UITextView! selectedContactsDisplay.delegate = self selectedContactsDisplay.backgroundColor = UIColor.appColor() selectedContactsDisplay.textColor = UIColor.white selectedContactsDisplay.textContainer.maximumNumberOfLines = 1 selectedContactsDisplay.textContainer