core-text

Word wrap detecting in UITextView

我的未来我决定 提交于 2020-01-04 13:11:36
问题 I am implementing a customized rich text editor by extending the UITextView. When user selects the text range and apples the 'highlighting' menu, the editor will draw a blue background for the selected text: - (CGRect)getRectAtRangePos:(NSInteger)pos { UITextPosition *beginning = self.beginningOfDocument; UITextPosition *start = [self positionFromPosition:beginning offset:pos]; CGRect rect = [self caretRectForPosition:start]; return [self convertRect:rect fromView:self.textInputView]; } -

FontName from CTFontRef

柔情痞子 提交于 2020-01-04 08:23:24
问题 I've a CTFontRef variable. CTFontRef aFontRef; Getting Size of Font was easy : CGFloat aFontSize = CTFontGetSize(aFontRef); Please help me in retrieving the FontName. I'm expecting the FontName to be something like MarkerFelt-Wide . But, when I use methods like CTFontCopyFullName(aFontRef) I get Marker Felt Wide Cheers Roshit 回答1: Looks like you want the PostScript name, which you can obtain through CTFontCopyPostScriptName(). The PostScript name is an internal name, and is generally the

NSForegroundColorAttributeName not working for UILabel

最后都变了- 提交于 2020-01-03 09:24:10
问题 I have a problem changing substring color using "NSForegroundColorAttributeName". I'm confused since other attributes for the same substring are being applied(underline). Also tried to use deprecated attribute "UITextAttributeTextColor" and other suggested attribute "kCTForegroundColorAttributeName" and got the same effect. I'm compiling for iOS 7. NSString *freeText = [NSString stringWithFormat:@"(%@)", self.me.activity.text]; int lblMaxWidth = arrImgView.origin.x - WPRConstraints

A string with '-' character is not drawing properly in drawrect method in iOS

两盒软妹~` 提交于 2020-01-03 06:04:56
问题 I'm working on coretext in iOS. I have implemented a custom UIView by replacing -drawRect method with the following code: - (void)drawRect:(CGRect)rect { [super drawRect:rect]; CGRect frameRect=CGRectMake(50, 200, 80, 15); // NSString *textToDraw=@"A-BCDEFGHIJKLM"; // NSString *textToDraw=@"abc"; // NSString *textToDraw=@"ABCDEFGHIJKLMNOPQRST"; NSString *textToDraw=@"A-BCDEFGHIJ"; // NSString *textToDraw=@"A-BCDEFGHI"; CFStringRef stringRef = (__bridge CFStringRef)textToDraw;

How do I draw text on a background thread in iOS?

为君一笑 提交于 2020-01-03 03:00:30
问题 I need to draw text on a background thread to save it as an image. I'm doing UIGraphicsPushContext() [NSString drawInRect:] UIGraphicsPopContext() The code works fine, but sometimes it crashes in drawInRect when I'm also drawing on the main thread at the same time. I tried to use NSAttributedString as suggested here: UIStringDrawing methods don't seem to be thread safe in iOS 6. But [NSAttributedString drawInRect:] doesn't seem to render anything on my background thread for some reason. Main

is this CoreText? - Aviary text pinch zoom expand

青春壹個敷衍的年華 提交于 2019-12-31 22:49:09
问题 I am looking into making an app where a user can change the size and orientation of UITextField . I was looking into Aviary app and what I see is that users can not only increase or decrease the size of the text but they can also change its orientation. So the questions I want to ask are 1) Are they using CoreText to do this are they using just plain old UILabel or UIText ? 2) I don't know how you can dynamically resize? Are they using UIView ? 3) I have googled CoreText tutorials, examples,

Super/Subscript appear to be broken in iOS13 (NSAttributedString)

十年热恋 提交于 2019-12-31 07:18:07
问题 Trying to display super/subscript text using NSAttributedString in a UITextView seems broken in iOS13 - unless anyone knows otherwise? Curiously if I use the UIFont systemFont then it works - but if I use any other font it doesn't. See below for my code to setup a UITextView in my test app. - (void)viewDidLoad { [super viewDidLoad]; UIFont* font = [UIFont systemFontOfSize:32]; //UIFont* font = [UIFont fontWithName:@"Helvetica Neue" size:32]; //UIFont* font = [UIFont fontWithName:@"Courier"

iOS: finding correct font size to fit in a UILabel depending on its size

会有一股神秘感。 提交于 2019-12-31 05:45:09
问题 I have a UILabel whose property text I would like to set paragraphs of text to using NSString . I have an array in which I store a sequence of characters that represent a text paragraph. The paragraph doesn't have to fit/included perfectly within this UILabel . If the paragraph doesn't end, I would move on to the next label. Let say if I had rect size of this UILabel 160 X 240, how could I be able to determine the correct font size in order to fill this string of the UILabel within nicely? Is

Aligning multiple sized text vertical center instead of baseline with Core Text in iOS

試著忘記壹切 提交于 2019-12-30 07:52:10
问题 Is it possible to align multiple sized text by bounding center (of each size) instead of baseline? I tried CTRunDelegate feature, but it doesn't work. It was possible with CTRunDelegateCallbacks.getAscent and CTRunDelegateCallbacks.getDescent , but the feature doesn't work. Only CTRunDelegateCallbacks.getWidth worked. I succeed to laying out multiple sized text, images, and any objects, but only baseline-alignment supported. 回答1: The run delegate methods getAscent and getDescent are, in fact,

Core Text's CTFramesetterSuggestFrameSizeWithConstraints() returns incorrect size every time

江枫思渺然 提交于 2019-12-29 03:11:12
问题 According to the docs, CTFramesetterSuggestFrameSizeWithConstraints () "determines the frame size needed for a string range". Unfortunately the size returned by this function is never accurate. Here is what I am doing: NSAttributedString *string = [[[NSAttributedString alloc] initWithString:@"lorem ipsum" attributes:nil] autorelease]; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef) string); CGSize textSize =