How should I override to change the spacing between lines in UILabel? Thanks
Next thread discusses alternatives to manage UILabel line spacing.-
How to control the line spacing in UILabel
Related
Rounded edges are getting kind of old, and I want my program to have a modern edge. Any idea how this can be done?
To clarify: I want the exact functionality of UITextField without rounded corners.
EDIT: Sorry, I'm a dumbass. I couldn't find the button because the textbox wasn't selected.
{insert facepalm emoticon here}
Just to help anyone who still runs into this, since it isn't clear enough you can use the Storyboard/Xib Interface Builder:
You can just change the borderStyle property of your UITextfield, or provide your own background image by setting backgroundImage property, here is a ref UITextField reference
Subclass UITextfield and override the drawrect: method. I think this should solve your problem.
You can modify a standard UITextView created in Interface Builder in viewDidLoad as follows:
[_textField setBorderStyle:UITextBorderStyleNone];
[_textField setBackgroundColor:[UIColor whiteColor]];
This can also be set the border style and background color directly in Interface Builder.
You need to set a background image and the background color.
UITextField *txtSearchField = [self.searchDisplayController.searchBar valueForKey:#"_searchField"];
[txtSearchField setBackgroundColor:[UIColor whiteColor]];
[txtSearchField setBackground:[[UIImage alloc]init]];
I made a CALayer *sublayer over the main view, then I added CATextLayer over sublayer.
Now I want to show text on the CATextLayer by clicking a button on my main view.
How can I do this?
Set the buttons action using -[UIButton addTarget:selector:forControlEvents:]:, then in that function set the CATextLayers string property to either an NSString or an NSAttributedString.
I remind you that CATextLayer doesn't respect paragraph settings on attributed strings, so line height is kind of off and does not look so great.
I have a UITableViewCell subclass (set up in IB). When entering editing mode, the autoresizing masks do their job and resize some UILabels. But when a cell scrolls out of screen, the UILabel seems to resize itself and the text then runs off the screen. Even when ending editing mode, the text doesn't resize back to normal. What can I do to prevent this?
Edit: I should also mentioned, my autoresizing masks for the UILabel are Content Mode Left and Flexible Width. Again, they seem to do their job when first entering editing mode.
I was able to fix it by manually resizing the UILabel in cellForRowAtIndexPath like so:
if (tableView.editing) {
cell.previewLabel.frame = CGRectMake(previewFrame.origin.x,
previewFrame.origin.y,
217,
previewFrame.size.height);
} else {
cell.previewLabel.frame = CGRectMake(previewFrame.origin.x,
previewFrame.origin.y,
237,
previewFrame.size.height);
}
Still, this is kind of ugly to me, so I'll gladly accept a better solution.
I have a UIScrollView which has a subview UITextView. When I added text to UITextView by code, the view is scrolling to the last line. I want the view not to scroll when I add text to UITextView by code. Anyone can help me fix the problem?
Finally I can fix my problem.
We just set YES the setScrollEnabled in UITextView before we change the text in UITextView and set NO after we change the text.
Here the example code
[yourTextView setScrollEnabled:YES];
yourTextView.text = [someString copy];
[yourTextView setScrollEnabled:NO];
:)
How would I give a NSTextView some padding/a margin to the left?
I know how you do it in a NSTextField (by subclassing NSTextFieldCell) but how do you do it in a NSTextView?
EDIT: A bit more info:
1. The Text View just has plain text no rich text and no other fancy stuff like a proper text editor (e.g Paragraph insets).
2. Is it possible to use setTextContainerInset: for this?
You could try subclassing NSTextView and override the textContainerOrigin.
Details here.
For example this subclass will give a top and bottom margin of 5 left of 20 and right of 10.
#implementation MyTextView
- (void)awakeFromNib {
[super setTextContainerInset:NSMakeSize(15.0f, 5.0f)];
}
- (NSPoint)textContainerOrigin {
NSPoint origin = [super textContainerOrigin];
NSPoint newOrigin = NSMakePoint(origin.x + 5.0f, origin.y);
return newOrigin;
}
#end
Just to add an update to this. iOS7 adds a property to UITextView called textContainerInset. Calling setTextContainerInset will create margins inside the TextView for the content.
The way TextEdit does it (when in Wrap to Page mode) is to put the text view inside of a larger view, and set that larger view as the document view of the scroll view. That's more work to set up, but won't leak presentation information (in the form of a specially-customized paragraph style) into the model (the text).
Create a mutable paragraph style (most probably by making a mutable copy of the default paragraph style, then set its head indent and first-line head indent to the left margin you want. Then, set this paragraph style as the value of the NSParagraphStyleAttributeName attribute for the entire contents of the view's text storage.
Note that this will show up in RTF and possibly HTML data obtained from/given to you by the view. If the view is not read-only (i.e., the user can edit the text and you will retrieve or receive that text from the view), then you should probably avoid this solution. If the user can show the ruler and edit the paragraph style themselves, then you should definitely avoid this solution.
This is all it takes when using a NSTextView with plain text style :
textView.textContainerInset = NSSize(width: 15, height: 5)