nsstring

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

好久不见. 提交于 2019-12-02 10:33:15
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 there a mathematical way for the calculation of font size based upon the size of the rect on the

iphone - display encoded characters like å,ä,ö in UILabel

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 10:32:27
问题 I have a list that uses UILabel for each of its rows. If I try to display special characters such as å,ä,ö, it displays them as &aring &auml &ouml How do I convert them into a UTF8 encoded NSString? 回答1: The characters display correctly in a WebView because the HTML entities are correctly interpreted by it. Maybe this handy NSString category can help you to display the text how you want in a UILabel: https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/NSString+HTML.m Import both

Reading a RTF file and parse plaintext

蓝咒 提交于 2019-12-02 09:51:27
I am doing this to get the content of a file using NSOpenPanel, but I am getting a lot of weird stuff returned from the .rtf file I select. My panel code: var panel: NSOpenPanel = NSOpenPanel() var fileTypesArray: NSArray = ["txt", "rtf", "nil"] panel.canChooseFiles = true panel.allowedFileTypes = fileTypesArray as [AnyObject] panel.allowsMultipleSelection = false if panel.runModal() == NSModalResponseOK { var url = panel.URL!.path println(url) let path = url let expandedPath = path!.stringByExpandingTildeInPath let data: NSData? = NSData(contentsOfFile: expandedPath) if let fileData = data {

Inserting Unicode Hyphen-minus into String Causes Error

大憨熊 提交于 2019-12-02 09:32:59
I am trying to insert a unicode hyphen-minus character into a text string. I am seeing an "Invalid universal character" error with the following: u+002D (hyphen-minus) [textViewContent insertString:@"\u002D" atIndex:cursorPosition.location]; However, these work fine: u+2212 (minus) [textViewContent insertString:@"\u2212" atIndex:cursorPosition.location]; u+2010 (hyphen) [textViewContent insertString:@"\u2010" atIndex:cursorPosition.location]; I've poked at several of the existing Unicode discussions here, but I have not found one that explains what is different amongst my examples that causes

iOS: Objective-C creating class property error: Use of undeclared identifier

时光怂恿深爱的人放手 提交于 2019-12-02 09:11:35
I'm trying to use class property following this example . But I'm getting the following error:"Use of undecleared identifier '_myProperty'". Here is my implementation: @interface myClass() @property (class,strong,nonatomic) NSString *myProperty; @end + (NSString*)myProperty { if (!_myProperty) { } return [NSString new]; } Why I'm getting this error? or any of you knows a work around this? I'll really appreciate your help Class properties don't get synthesized in Objective-C. You have to provide your own backing variable and your own getter/setter: static NSString *_myProperty = nil; +

[iOS Animation]-CALayer 专用图层 CATextLayer

守給你的承諾、 提交于 2019-12-02 09:03:28
CATextLayer 用户界面是无法从一个单独的图片里面构建的。一个设计良好的图标能够很好地表现一个按钮或控件的意图,不过你迟早都要需要一个不错的老式风格的文本标签。 如果你想在一个图层里面显示文字,完全可以借助图层代理直接将字符串使用Core Graphics写入图层的内容(这就是UILabel的精髓)。如果越过寄宿于图层的视图,直接在图层上操作,那其实相当繁琐。你要为每一个显示文字的图层创建一个能像图层代理一样工作的类,还要逻辑上判断哪个图层需要显示哪个字符串,更别提还要记录不同的字体,颜色等一系列乱七八糟的东西。 万幸的是这些都是不必要的,Core Animation提供了一个CALayer的子类CATextLayer,它以图层的形式包含了UILabel几乎所有的绘制特性,并且额外提供了一些新的特性。 同样,CATextLayer也要比UILabel渲染得快得多。很少有人知道在iOS 6及之前的版本,UILabel其实是通过WebKit来实现绘制的,这样就造成了当有很多文字的时候就会有极大的性能压力。而CATextLayer使用了Core text,并且渲染得非常快。 让我们来尝试用CATextLayer来显示一些文字。清单6.2的代码实现了这一功能,结果如图6.2所示。 清单6.2 用CATextLayer来实现一个UILabel @interface

passing the value from one class to other class

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 08:39:18
I am facing the problem in displaying the value of string of AddNotesViewController Class , in the Label of the DetailsOfPeopleViewController . All i want to do is whatever we entered in the UITextView of 1 class,should display in the UILabel of another class. In file AddNotesViewController.h UITextView *txtView; @property(nonatomic,retain)IBOutlet UITextView *txtView; in file AddNotesViewController.m @synthesize txtView; After this when i click on the tab bar item "save" then it should save in the data base , its saving to database and displaying the value also but its not passing the value

iPhone Dev - NSString Creation

拈花ヽ惹草 提交于 2019-12-02 08:29:15
I'm really confused with NSStrings. Like when should I do NSString *aString = @"Hello"; of should it be: NSString *aString = [[NSString alloc] initWithString:@"Hello"]; But then its different when you're assigning a value to an NSString property isn't it? Can someone clear this up for me? Thanks!! In general you should do the first, but they are mostly functionally the same. You can treat constant NSStrings just like normal NSString string objects, for instance: [@"Hello" length] will return 5. You can assign them to properties, everything just works. The one thing you might notice is that

How to print a NSString from a DTrace script

元气小坏坏 提交于 2019-12-02 08:29:07
问题 This question is asking the same thing, but when I tried: typedef long long ptr_t; objc$target:NSWindow:-setTitle?:entry { printf( "%30s %10s %x %x %x\n", probemod, probefunc, arg0, arg1, arg2 ); this->str = *(ptr_t*)copyin(arg2+2*sizeof(ptr_t), sizeof(ptr_t)); printf("string addr = %p\n", this->str); printf("string val = %s\n", copyinstr(this->str)); } It didn't work. arg2 should be the address of the NSString. I got: NSWindow -setTitle: 100685240 7fff92d82f73 7fff78a6eb80 string addr =

How to print a NSString from a DTrace script

元气小坏坏 提交于 2019-12-02 08:19:11
This question is asking the same thing, but when I tried: typedef long long ptr_t; objc$target:NSWindow:-setTitle?:entry { printf( "%30s %10s %x %x %x\n", probemod, probefunc, arg0, arg1, arg2 ); this->str = *(ptr_t*)copyin(arg2+2*sizeof(ptr_t), sizeof(ptr_t)); printf("string addr = %p\n", this->str); printf("string val = %s\n", copyinstr(this->str)); } It didn't work. arg2 should be the address of the NSString. I got: NSWindow -setTitle: 100685240 7fff92d82f73 7fff78a6eb80 string addr = 7fff8e7e83b9 string val=Window dtrace: error on enabled probe ID 5 (ID 35737: objc9434:NSWindow:-setTitle: