How do I format static text (not editable) in a UITextView? I'm trying to implement a "Help" page without going through a UIWebView...
You can use a UILabel instead.
Related
I have a UITextView and I am inserting images into using NSTextAttachment. The problem is that when the user moves the cursor after the image and begins to type text, instead of using the font used everywhere else in the UITextView, it resets to a smaller font.
How can I make sure that the font that is typed after an image is the same font as the one typed elsewhere?
I ended up reseting the typingAttributes after each time the cursor is changed. I have not found any cases where this doesn't work as expected.
extension ViewController: UITextViewDelegate {
func textViewDidChangeSelection(textView: UITextView) {
textView.typingAttributes = defaultAttributes
}
}
I want to be able to highlight a portion of text in an NSTextField but I've not been able to Google a way of doing this.
I have defined an NSRange but I cannot find a way of using this range to highlight the text. The only thing I have turned up is textField.selectText but this supposedly highlights the whole field.
I'm using Swift 2.
You may have noticed that an NSTextField only shows a selection range when it has focus, i.e., is the first responder. In this case, editing is handled by an NSTextView called the field editor. So, make sure the field has focus (e.g., by using the makeFirstResponder: method of NSWindow), then use the NSControl method currentEditor to get the field editor, and then you can use the NSText method setSelectedRange:.
ObjC
NSText* fieldEditor = [myField currentEditor];
[fieldEditor setSelectedRange: mySelRange];
Swift
let fieldEditor = textfield.currentEditor()
fieldEditor?.selectedRange = range
I have working program with Wrapping Text Fields, and I would like to add vertical scrolling. I have found that there is Text View object in xcode library and it has NSTextView in NSScrollView. The problems came when I simply tried to substitute Text Fields with Text View. First, when I made outlet, this outlet belongs to NSScrollView (no NSTextView), and NSScrollView doesn't have String type, which I need for working code. Second, when I deleted NSScrollView (I don't know if it was right to do this) and typed instead NSTextView in outlet, I could use type string, but code didn't work. What I did wrong, what should I do ?
Add an UITextView
Drag an outlet from it to your class
Make this class implement UITextViewDelegate
In code, set this text views delegate to this class
It is really simple, I'm confused by steps you took to try to get it working.
I would like to create a tag cloud of sorts, and I thought of using a UITextView. Is it possible to have variable text sizes in a UITextView? If not, any other suggestions on which UI elements to use to generate a tag cloud?
I would recommend programmatically adding UILabel objects as needed. You can only have one font size per UITextView, plus UITextView is generally for editable text. Just roughly, you could use something like this:
UILabel *example = [[UILabel alloc] initWithFrame:<#(CGRect)#>];
[example setFont:<#(UIFont *)#>];
[example setText:<#(NSString *)#>];
[self.view addSubview:example];
You can put it in a loop and fill in the blanks.
It should be possible in iOS 6 (if you can wait that long) since Apple is finally adding the possibility to use NSAttributedString in UITextView.
I have a NSTableView where I would like to have text elipsis in cells. Do you know how I have to proceed?
Thanks in advance for your help,
Regards,
AP
In the datasource method objectValueForTableColumn you need to create a NSAttributedString with your desired text format and return it.
Create a paragraph style and set its line break mode.
[pStyle setLineBreakMode: NSLineBreakByTruncatingTail]
Then set the paragraph style as an attribute to the attributed string.