How can I change font color in header of NSTableView?
In Xcode Interface Builder - any color modifications in Font Panel of Table Column properties are ignored / discarded.
Also I can not find a proper information my problem in Apple documentation.
Does anyone know is it possible ?
For each of the NSTableColumns in the [NSTableView tableColumns], do:
[[yourColumn headerCell] setAttributedStringValue:yourNSAttributedString].
The font color will be keyed to NSForegroundColorAttributeName in your string attribute dictionary.
Related
Clarification: First, cursor = the insertion point cursor, not the mouse cursor.
Ok, I would like to return the font / font size / font color wherever the cursor is in the NSTextView. I tried using attribute:atIndex:effectiveRange:, but I failed because I got my variables all mixed up. I think it is what I need. Some example code would just be appreciated, returning the font. I think it will work the same for font size/color, I'll just have to substitute NSFontAttributeName for something else, right? Thanks in advance!
NSFont *font = [textView.textStorage attribute:NSFontAttributeName atIndex:textView.selectedRange.location effectiveRange:nil];
Should work for all getting the name.
What have you tried?
NSTextView has a method selectedRanges which returns the current selection(s) - just one of zero-length if there is just an insertion point.
NSTextView also has a property textStorage which returns back the instance of NSTextStorage which holds the text. An NSTextStorage inherits from NSMutableAttributedString, which inherits from NSAttributedString, and that has methods to obtain the attributes of the text.
Combined those two and you have your answer.
HTH
I am working with interface builder to create a xib. This xib has a uiview that contains a uitextview. Both are supposed to resize as the text in the uitextview changes. The constraints look a lot like this:
The pink UITextView pushes on the blue superview. The blue uiView has a minimum width of 189 px and a trailing constraint of at least 8px.
For the most part this works. Really long sections of text resize the two views to the fullest extent allowed as intended and if there are only one or two words, the views stay small. However, the problem is when you have a short sentence.
In this case, the views only expand to about 189px, and the text moves to the second line even though there is space to expand.
Here is what it looks like when you only put a few words in:
and here is a fully expanded box:
I have tried to make the trailing constraint have a lower priority than the others, and I have tried modifying the content hugging and compression resistance properties in many ways without success.
How can I make the views expand so that they fit the text content with the fewest number of lines? There are no restrictions on height, only on width.
Any help would be appreciated!
Get the new size of the textView using this method
CGSize sz = [_textView.text sizeWithFont:_textView.font]
in case that didn't work very well with the height,get the width you just got from the preivous method and use in the next method to get the appropriate height you need
- (CGFloat)textViewHeightForAttributedText:(NSAttributedString *)text andWidth:(CGFloat)width
{
UITextView *textView = [[UITextView alloc] init];
[textView performSelectorOnMainThread:#selector(setAttributedText:)
withObject:text
waitUntilDone:YES];
CGSize size = [textView sizeThatFits:CGSizeMake(width, FLT_MAX)];
return size.height;
}
The key is to set the preferredMaxLayoutWidth to something big (320px sounds good. Your right constraint is going to limit it anyways).
You can do that in your code as
[self.label setPreferredMaxLayoutWidth:320];
Or from the Interface Builder as follows:
This way you'll see the label expanding as expected:
Have you tried the solution presented in this post?
Dynamic expand UITextView on ios 7
I believe you have to set your UITextView to sizeToFit
[YourUITextView sizeToFit];
I am uising this code for marquee effect. i want digital clock like font so i gave font as
UIFont *lcdFont = [UIFont fontWithName:#"DBLCDTempBlack" size:60.0];
self.font = lcdFont ;
But i am getting this font only for some random characters.I am using only uppercase letters. I want i for all the characters in UILabel.
Why is it happening so.
It's nothing wrong with your code -- that font only has certain characters in it. (Why? Who knows.) For those it's missing, the OS automatically falls back to another font.
If you want to draw LCD-looking text using a broader character set, you'll need to find such a font elsewhere and bundle it in your app.
What is a good way to determine the current height of the content height in a UITextView?
Look in UIStringDrawing.h for various text measuring functions. You probably want something like:
[myTextView.text sizeWithFont:myTextView.font forWidth:myTextView.bounds.width lineBreakMode:UILineBreakModeWordWrap].height;
If you just want to know what the text view is using, then use:
[myTextView contentSize].height;
I have built a color well using objective c and cocoa but I am having trouble getting the color out using takeColorFrom:. My example would not be useful because I am writing all this in lisp with an objective c bridge. Could someone link me to an example of how to do this in objective C and I can easily translate from that.
'takeColorFrom:' is to set the color of your well from an external object. You probably want the 'color' method, which returns the color of your NSColorWell object.
From the documentation:
color
Returns the color of the receiver.
- (NSColor *)color
Return Value
The color of the receiver.
takeColorFrom:
Changes the color of the receiver to that of the specified object.
- (void)takeColorFrom:(id)sender
Parameters
sender
The object from which to take the new color.