core-text

How to add background color and rounded corners for Strings in iOS?

血红的双手。 提交于 2021-02-06 12:52:54
问题 How to add background color and rounded corners for Strings in iOS? like this picture below: Can't do it with NSAttributedstring . So, should I use CoreText ? I found this answer but still don't know how to do it. 回答1: String is just a data in text format, it's not visual. You need labels, those are labels there. And then set your string to that label. let label = UILabel() label.backgroundColor = .green label.text = "Label" // You set your string to your label label.layer.cornerRadius = 5

How to add background color and rounded corners for Strings in iOS?

怎甘沉沦 提交于 2021-02-06 12:51:18
问题 How to add background color and rounded corners for Strings in iOS? like this picture below: Can't do it with NSAttributedstring . So, should I use CoreText ? I found this answer but still don't know how to do it. 回答1: String is just a data in text format, it's not visual. You need labels, those are labels there. And then set your string to that label. let label = UILabel() label.backgroundColor = .green label.text = "Label" // You set your string to your label label.layer.cornerRadius = 5

How to avoid memory leak with CTFontCreateWithGraphicsFont?

吃可爱长大的小学妹 提交于 2021-01-27 06:19:28
问题 I've reduced a leak issue to this easy to compile code which shows after CTFontCreateWithGraphicsFont use and release ct_font , an extra ref to cg_font will be left. Is this an internal Apple ref count issue or am I missing something around like having to double release cg_font or changing order of the releases? Thanks. #include <stdio.h> #include <stdlib.h> #include <ApplicationServices/ApplicationServices.h> int main(int argc, char **argv) { FILE *f = fopen("/Library/Fonts/Tahoma.ttf", "rb"

Line spacing and paragraph alignment in CoreText

六月ゝ 毕业季﹏ 提交于 2020-01-21 03:35:08
问题 I am using CoreText to render multiple columns of text. However, when I set the first letter of the 1st paragraph to a bold, larger font than the rest of the text, I incur 2 issues (both visible in the attached image): The spacing underneath the first line is too big (I understand that this is because the 1st character could be a g,y,p,q etc. Lines below the first line now do not line up with corresponding lines in the next column. Any advice on how to overcome these 2 issues would be greatly

Custom UITableViewCell With Core Text

谁说我不能喝 提交于 2020-01-14 06:20:29
问题 Using the help of @yaslam I've created in Core Text an UILabel that show Japanese text in both horizontal and vertical way with Furigana using CTRubyAnnotation. Unfortunately I've a problem. I need to use this label inside a custom cell and I need that the cell dynamically resize the height of the cell based on text. but don't work. the cell doesn't expands Can you help me? Thank you very much Here's code import UIKit protocol SimpleVerticalGlyphViewProtocol { } extension

iOS CoreText CTLineGetStringRange with CTLineRef from CTLineCreateTruncatedLine

纵然是瞬间 提交于 2020-01-14 04:54:19
问题 I have the following code in iOS: CFAttributedStringRef attributedString = ... CTLineRef line = CTLineCreateWithAttributedString(attributedString); CTLineRef truncatedLine = CTLineCreateTruncatedLine(line, 50.0, kCTLineTruncationEnd, NULL); CFRange lineRange = CTLineGetStringRange(line); CFRange truncatedLineRange = CTLineGetStringRange(truncatedLine); My lineRange is the same as truncatedLineRange. Why? The documentation makes no mention of this. 回答1: According to the coretext-dev mailing

Calculate Font Size to Fit Frame - Core Text - NSAttributedString - iOS

假如想象 提交于 2020-01-10 08:48:08
问题 I have some text which I am drawing into a fixed frame via an NSAttributedString (code below). At the moment I am hard coding the text size to 16. My question is, is there a way to calculate the best fit size for the text for the given frame ? - (void)drawText:(CGContextRef)contextP startX:(float)x startY:(float) y withText:(NSString *)standString { CGContextTranslateCTM(contextP, 0, (bottom-top)*2); CGContextScaleCTM(contextP, 1.0, -1.0); CGRect frameText = CGRectMake(1, 0, (right-left)*2,

Define Core Text paragraphs without using newline character?

余生颓废 提交于 2020-01-07 06:19:21
问题 I am having a trivial problem with applying proper top and bottom spacing for the paragraphs in NSAttributedString. I am usng this code to set paragraph attributes: int sf = sizeof(CGFloat); CTParagraphStyleSetting settings[ParagraphStylesSupported] = { { kCTParagraphStyleSpecifierAlignment, sizeof(QuartzTextAlignment), &style.textAlignment }, { kCTParagraphStyleSpecifierParagraphSpacingBefore, sf, &marginTop}, { kCTParagraphStyleSpecifierParagraphSpacing, sf, &marginBot}, {

How to draw an NSString with an specific height on to an perfectly matching bitmap?

时光总嘲笑我的痴心妄想 提交于 2020-01-05 10:04:04
问题 I have an NSString like @"Hello World" and want to convert that into an bitmap with exactly 20 pixels height. The width of the bitmap should match the width of the text. I know there are some NSString UIKit additions that can draw text, but I don't know how to draw the text with an bounding box of exactly 20 pixels height (text fits perfectly into this height) into an bitmap that has the perfect size to carry the text? Is there an easy way to do this? This must also work with Chinese,

How to draw an NSString with an specific height on to an perfectly matching bitmap?

半世苍凉 提交于 2020-01-05 10:04:01
问题 I have an NSString like @"Hello World" and want to convert that into an bitmap with exactly 20 pixels height. The width of the bitmap should match the width of the text. I know there are some NSString UIKit additions that can draw text, but I don't know how to draw the text with an bounding box of exactly 20 pixels height (text fits perfectly into this height) into an bitmap that has the perfect size to carry the text? Is there an easy way to do this? This must also work with Chinese,