nsattributedstring

Displaying text one character at a time in swift 2.0

扶醉桌前 提交于 2019-11-28 11:42:58
New to Swift 2.0; trying to learn it, interested in animation and tried to write some code to display a message on screen one character at a time. I wrote this, it works, but I cannot help but could I not do something with CALayers perhaps and/or alpha values? Or some animate gizmo, something more swift worthy; this feels & looks kinda clunky, sort 1977 really. import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let supertext = "A long time ago, in a galaxy far, far away

UITextField attributedPlaceholder has no effect

白昼怎懂夜的黑 提交于 2019-11-28 10:54:56
I'm trying to make the placeholders in my textfields italic, and since my app is targeting iOS 6.0 or newer, decided to use attributedPlaceholder property instead of rolling something more custom. The code goes as follows: NSString *plString = @"optional"; NSAttributedString *placeholder = [[NSAttributedString alloc] initWithString:plString attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-LightItalic" size:15]}]; for (UITextField *t in myTextfields){ t.placeholder = plString; t.attributedPlaceholder = placeholder; } Yet the styling of the placeholder still is not italic,

Cannot convert value of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?'

这一生的挚爱 提交于 2019-11-28 10:46:05
How to convert values of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?' ? open class func drawText(context: CGContext, text: String, point: CGPoint, align: NSTextAlignment, attributes: [String : AnyObject]?) { var point = point if align == .center { point.x -= text.size(withAttributes: attributes).width / 2.0 } else if align == .right { point.x -= text.size(withAttributes: attributes).width } NSUIGraphicsPushContext(context) (text as NSString).draw(at: point, withAttributes: attributes) NSUIGraphicsPopContext() } This is a new feature of Swift 4. All

How to use store and use an NSMutableAttributedString in NSUserDefaults

自古美人都是妖i 提交于 2019-11-28 10:31:08
I want to create an attributed string, then store it in NSUserDefaults , and then access it again and assign the attributed string to textView.attributedText . How do I go about this? Thanks in advance. I don't know a lot of objective c, so I could not refer to this answer You have to convert your NSMutableAttributedString into NSData then you store it in NSUserDefaults . // Convert into NSData let data = NSKeyedArchiver.archivedDataWithRootObject(distanceMutableAttributedString) NSUserDefaults.standardUserDefaults().setObject(data, forKey: "yourStringIntoData") // Convert your NSData to

Changing Background color on NSAttributedString

不羁的心 提交于 2019-11-28 07:29:55
问题 I just wanted to know how could i change the background color of an NSAttributedString, i can see the background being white all the time, but i want to make it black. Is that possible?? Many thanks! 回答1: I think you want NSBackgroundColorAttributeName. Such as: [mutableAttributedString addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:selectedRange]; 回答2: The best plan would really be to draw the string on a view with a black background. 回答3: For swift 3.x

Change font size without Change UITextView attributedText

蹲街弑〆低调 提交于 2019-11-28 07:05:39
问题 I try to change a font size in my UITextView and every time I change the attributedText was restore to default. with this I make the middle test bold : str = [[NSMutableAttributedString alloc] initWithAttributedString:string]; [str addAttribute:NSFontAttributeName value:newFont range:NSMakeRange(range.location, range.length)]; before: that was bold font in the middle. after :all the text bold I want that after the size change the bold stay where he be. Edit : I try with this two ways : 1)

Why does the initial call to NSAttributedString with an HTML string take over 100 times longer than subsequent calls?

此生再无相见时 提交于 2019-11-28 05:54:39
I had a need to display HTML text inside my iOS app. I have decided I will use the built-in method on NSAttributedString , initWithData:options:documentAttributes:error: . The actual parsing works excellently, however, I seem to have come across a very odd bug, that only seems to manifest itself if I have the debugger attached. The first time that this method is called, it takes barely under 1 second to run on my iPhone 5S running iOS 7.0.4, and about 1.5 seconds on an iPod Touch 5th generation. The quirk also manifests itself on the simulator, but it is significantly less noticeable, due to

Attributed Text Center Alignment

大憨熊 提交于 2019-11-28 05:10:33
I have tried everything but cannot seem to center this text. Can someone please tell me where the error is. NSMutableParagraphStyle *paragraphStyle = NSMutableParagraphStyle.new; paragraphStyle.alignment = NSTextAlignmentCenter; label.attributedText = [[NSAttributedString alloc] initWithString:cell.EventTitle.text attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSParagraphStyleAttributeName:paragraphStyle,NSBaselineOffsetAttributeName : @0,NSFontAttributeName : [UIFont fontWithName:@"BrandonGrotesque-Black" size:34]}]; Shrawan In Swift-4 let paragraph =

NSAttributedString inserting a bullet point?

老子叫甜甜 提交于 2019-11-28 03:50:52
So I have an NSAttributedString I want to insert a bullet point at the beginning of a portion of text. How can I do this? How do I create a CTPAragraphStyle that creates this bullet point when I display the text? Edit: Should be available on iOS The easy bit: [mutableAttributedString insertAttributedString: @"•\t" atIndex:0]; The hard bit. Something along the following lines. (This is extracted from a bigger project, but it may give you a decent start.) NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"•\texample bullet fill out the text to check what

How can I concatenate NSAttributedStrings?

社会主义新天地 提交于 2019-11-28 03:25:01
I need to search some strings and set some attributes prior to merging the strings, so having NSStrings -> Concatenate them -> Make NSAttributedString is not an option, is there any way to concatenate attributedString to another attributedString? I'd recommend you use a single mutable attributed string a @Linuxios suggested, and here's another example of that: NSMutableAttributedString *mutableAttString = [[NSMutableAttributedString alloc] init]; NSString *plainString = // ... NSDictionary *attributes = // ... a dictionary with your attributes. NSAttributedString *newAttString = [