nsattributedstring

lineSpacing property inside UILabel doesn't work as expected

守給你的承諾、 提交于 2019-12-12 00:33:12
问题 I am trying to create a custom UILabel class which will allow me to increase the line spacing on a UILabel. I know you can do this in IB with an attributed text string, however it doesn't work if you are using custom fonts. Here is my class code: import UIKit @IBDesignable class SpacingLabel: UILabel { @IBInspectable var lineSpacing: CGFloat = 10.0 override func awakeFromNib() { self.renderText() } override func prepareForInterfaceBuilder() { super.prepareForInterfaceBuilder() self.renderText

Draw line in UILabel before and after text

人走茶凉 提交于 2019-12-11 20:01:46
问题 I want to draw a line before and after a string in UILabel exactly like the following image: PS: the text is not static, so i can't tell what is the exact text width, otherwise i would put two static lines before and after the text. PS: Also i can't put the label above a line and give the label background color same to the view background because i have gradient color in the lower view. 回答1: I Hope below is what you was looking for... #import "ViewController.h" @interface ViewController () {

UIBarButtonItem color setting in Swift-5.0

时光总嘲笑我的痴心妄想 提交于 2019-12-11 18:03:46
问题 I realised that the color-behaviour of my UIBarButtonItem's (left and right buttons) is not as desired. If I press and hold the right UIBarButton (see video), then the color changes from light-yellow to gray'isch dark-yellow. However, I would like a solution that keeps the same light-yellow color, no matter of any button selection, press-and-hold, etc. The button color should always stay the same light-yellow. How can I achieve this ? Here is the video done in Simulator: (you can clearly see

Why isnt this variable an Attributed String?

醉酒当歌 提交于 2019-12-11 17:56:56
问题 I have these 3 lines in code which are meant to take text from a .txt file and allocate it to an NSAttributedString NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"]; NSString *text = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL]; NSAttributedString *attString = [[NSAttributedString alloc] initWithString:text]; Using the debugger I know that the path is being found correctly, and the text is being added to the variable text fine

HTML to attributed string to HTML increase font size for random text

痴心易碎 提交于 2019-12-11 17:52:42
问题 This is my HTML sample string. "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><title></title><meta name=\"Generator\" content=\"Cocoa HTML Writer\"><style type=\"text/css\">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 40.0px; font: 33.2px '.SF UI Text'; color: #000000; -webkit-text-stroke: #000000

NSAttributedString with padding before and after the text and a background

孤人 提交于 2019-12-11 15:59:43
问题 I want to style a text using NSAttributedString . The text should have a background and a custom padding, so that the text has a little bit of space to the background's edge. This is what I want to achieve: This is what I don't want to achieve (background in the second line is not word / character-specific): And this is the code that I tried in a playground: let quote = "some text with a lot of other text and \nsome other text." let paragraphStyle = NSMutableParagraphStyle() paragraphStyle

Swift - Font size increases when converting html string to attributed string and back again

人走茶凉 提交于 2019-12-11 14:59:25
问题 I have a textView that allow user to enter NSAttributedString, convert into html string and then store into database. I also have code to convert the html string back and display in textView for editing. The conversion codes I have are extension String { func htmlAttributedString() -> NSAttributedString? { guard let data = self.data(using: String.Encoding.utf16, allowLossyConversion: false) else { return nil } guard let html = try? NSMutableAttributedString( data: data, options:

How to properly compensate CGContextRef coordinate system, so the origin is at the top left corner

£可爱£侵袭症+ 提交于 2019-12-11 14:22:42
问题 I'm trying to draw text using CoreText. I have the following code: CGContextRef uiContext = UIGraphicsGetCurrentContext(); NSMutableDictionary<NSAttributedStringKey,id> *attributes = [NSMutableDictionary<NSAttributedStringKey,id> new]; [attributes setObject:UIColor.redColor forKey:NSForegroundColorAttributeName]; [attributes setObject:[UIFont systemFontOfSize:40] forKey:NSFontAttributeName]; NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"Str" attributes

UITextView Alternative

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 11:35:56
问题 As i understood from Apple docs attributedText property of UITextView: This property is nil by default. Assigning a new value to this property also replaces the value of the text property with the same string data, albeit without any formatting information. In addition, assigning a new a value updates the values in the font, textColor, and textAlignment properties so that they reflect the style information starting at location 0 in the attributed string. Therefore i cannot add an

How to subscript letters when not there is no glyph in system font?

拟墨画扇 提交于 2019-12-11 07:47:03
问题 I have been able to successfully subscript numbers in my app by doing: static const unichar kSubscriptZero = 0x2080; int numberOfHydrogens = 2; NSString *header1 = [NSString stringWithFormat:@"H%CO", kSubscriptZero + numberOfHydrogens]; The problem is this: I tried doing the same things with other characters that can be found in unicode characters but it did not work, all I got was a square box instead of my character, turns out that means that there is no glyph in my font for that character.