Sunday, February 24, 2013

iOS -- Constructing and Displaying Styled Texts

To display rich text formatted :

for example :     This is a car! , to display different styled text in one label.


The solution is use attributed text, here is the code,


To set the text to a label, use self.label.attributedText = [self attributedText];



Sunday, February 3, 2013

ios -- understand strong, weak, unsafe_unretained


In IOS 5, to use Automatic Reference Counting (ARC) in the latest LLVM compiler, we need to deal with storage that is strong, weak, or unsafe and unretained. Any object under ARC is managed with one of these storage attributes. Here is a short explanation for each one: 


strong
An object of this type is automatically retained at runtime and will be valid until the end of its scope, where it will automatically be released. For those familiar with Objective-C’s traditional way of memory management, this keyword is similar to the retain keyword. 



weak
This is zeroing weak referencing. If a variable is defined with this keyword, when the object to which this variable points gets deallocated, this value will get set to nil. For instance, if you have a strong string property and a weak string property and set the weak property’s value to the strong property’s value, when the strong property gets deallocated, the weak property’s value will get set to nil.


unsafe_unretained
This is simply pointing one variable to another. This will not retain the object into the new variable, it will simply assign the object to the variable. 


source from :  iOS6 Programming Cookbook