Tuesday, July 31, 2012

How to use NSAttributedString in iOS 6


infoString=@"This is an example of Attributed String";

NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:infoString];
NSInteger _stringLength=[infoString length];

UIColor *_black=[UIColor blackColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:30.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_black range:NSMakeRange(0, _stringLength)];



               






UIColor *_red=[UIColor redColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:3.0] range:NSMakeRange(0, _stringLength)];















UIColor *_red=[UIColor redColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0] range:NSMakeRange(0, _stringLength)];

















UIColor *_red=[UIColor redColor];
UIColor *_green=[UIColor greenColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_green range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0] range:NSMakeRange(0, _stringLength)];



















UIColor *_green=[UIColor greenColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];

NSShadow *shadowDic=[[NSShadow alloc] init];
[shadowDic setShadowBlurRadius:5.0];
[shadowDic setShadowColor:[UIColor grayColor]];
[shadowDic setShadowOffset:CGSizeMake(0, 3)];
              
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_green range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSShadowAttributeName value:shadowDic range:NSMakeRange(0, _stringLength)];
                



















UIColor *_red=[UIColor redColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
  [attString addAttribute:NSForegroundColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];              
  [attString addAttribute:NSKernAttributeName value:[NSNumber numberWithInt:5] range:NSMak








UIColor *_red=[UIColor redColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:30.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:2] range:NSMakeRange(0, _stringLength)];








UIColor *_blue=[UIColor blueColor];
UIColor *_blueL=[UIColor colorWithRed:0 green:0 blue:0.5 alpha:0.7];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:30.0f];
                
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_blue range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSBackgroundColorAttributeName value:_blueL range:NSMakeRange(0, 20)];


                

107 comments:

  1. Hi Reetu Raj

    i was stucked up over addingAttribute for attribute string,help me over that....
    when ever i call addattribute to attstr and when i add NSFontAttributeName getting error..help me over this

    ReplyDelete
  2. If you XCode doesn't recognize NSFontAttributeName, you are probably not using SDK 6.0

    ReplyDelete
  3. Hi Reetu Raj,

    Are you be able to use NSAttributedString in iOS 4.3? It gave me the error. Or is it only supported in iOS 6?

    ReplyDelete
  4. label is my UIlabel to which i want to add attributed text:

    label.attributedText = attString;

    OR

    [label setAttributedText: attString];

    Nice post, thanks a lot.

    ReplyDelete
  5. You can use either, its fine. Just keep it consistent throughout.

    ReplyDelete
  6. NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Iamthebest"];
    UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:25.0f];
    [attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0,1)];


    mLbl.attributedText=attString;

    This will make Character I as BOLD

    ReplyDelete
  7. Thanks for great and simple to understand tutorial on attributed string.

    Regards
    Aman
    http://www.amaniphoneblog.com

    ReplyDelete
  8. Thanks your blog is awesome.
    thanks for sharing information.

    Videocon 2.75G speed

    Videocon Telecom invests approx Rs 130 Cr to upgrade its network to 2.75G EDGE, a 3G standard technology, to enhance Customer experience on data speed. Rolls out a full-fledged marketing campaign to get Customer attention.

    ReplyDelete
  9. Hai Good information shared about IOS. In future everything about ios . This blog post is really helpful. Please keep updated tutorials…

    ReplyDelete
  10. Good Information and having excellent techniques. Now a days these mobile Technologies are been very specially designed and maintained as to get security from different Hackers Well when I completed my Project Management Professional Training in kuwait I was supposed to handle certain projects where I was able to configure about the security issues in mobile terms well I was having specific terms to determine the Technologies at that moment
    Thankyou so much for the blog well i want to see more from you which really help me a lot

    ReplyDelete
  11. I need to still get it working w/ everything NSAttributedString has to offer, but I think fontName, fontSize and color cover the bulk of it. Expect lots of updates soon :)

    I can help you get started with this if you need. Also looking for feedback, so if it makes your life easier, I'd say mission accomplished.
    For More Professional Path refer below.
    Oracle SCM Course
    Oracle Financials Course
    Hadoop Admin Course
    Microsoft CRM Dynamics Course

    ReplyDelete
  12. Thanks for sharing your valuable time with this article.
    btelinks
    Police Result

    ReplyDelete
  13. Really Good blog post.provided a helpful information.I hope that you will post more updates like this ios Online Training Bangalore

    ReplyDelete
  14. I have read your blog its very attractive and impressive. I like your blog. ios Online course Bangalore

    ReplyDelete
  15. Appreciate Your Work, Very informative Blog on Android Development, I would like to share some information on Android Development training which will help for the blog here.

    ReplyDelete
  16. Informative Blog on Mobile Development Technology... Thanks for your Valuable Information... MindMajix is providing Online Training on IOS Development Training.

    ReplyDelete
  17. The Best article, Bala Guntipalli This concept is a good way to enhance the knowledge.

    ReplyDelete
  18. Each department of CAD have specific programmes which, while completed could provide you with a recognisable qualification that could assist you get a job in anything design enterprise which you would really like.

    AutoCAD training in Noida

    AutoCAD training institute in Noida


    Best AutoCAD training institute in Noida

    ReplyDelete
  19. Thanks for sharing such an informative post...

    ReplyDelete
  20. Thanks for sharing such an informative post...

    ReplyDelete
  21. Nice blog with excellent information. Thank you, keep sharing.


    RPA Training in Hyderabad

    ReplyDelete
  22. Your blog is very useful for me, Thanks for your sharing.


    MSBI Training in Hyderabad


    ReplyDelete
  23. interesting blog, here lot of valuable information is available, it is very useful information. we offers this Android classroom and online training at low caste and with real time trainers. please visit our site for more details Android training

    ReplyDelete
  24. Thanks for sharing the great post. Love your blog and every post. Appreciateit.

    ReplyDelete
  25. Thanks For sharing this blog very useful content and more informative.
    SAP GRC Training

    SAP Hana admin Training

    ReplyDelete
  26. Thank you for providing useful information and this is the best article blog for the students.learn Oracle Fusion Financials Online Training.

    Oracle Fusion Financials Online Training

    ReplyDelete
  27. Thank you for sharing such a valuable article with good information containing in this blog.learn Oracle Fusion Technical Online Training.

    Oracle Fusion Technical Online Training

    ReplyDelete
  28. Thanks for sharing valuable information in the article.students can make a good career by learning Oracle Fusion SCM Online Training.

    Oracle Fusion SCM Online Training

    ReplyDelete
  29. Thanks for providing such a great information in the blog and also very helpful to all.learn best Oracle Fusion HCM Online Training.

    Oracle Fusion HCM Online Training

    ReplyDelete
  30. Hey Really Thanks for sharing the best information regarding oracle,hope you will write more great blogs.
    Oracle Fusion SCM Training In Hyderabad

    ReplyDelete
  31. Very interesting blog Awesome post. your article is really informative and helpful for me and other bloggers too
    Oracle Fusion HCM Online Training

    ReplyDelete
  32. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.
    Oracle Fusion Financials Online Training

    ReplyDelete
  33. Wonderful post. Thanks for taking time to share this information with us.

    Article submission sites
    Technology

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. Very good information about DevOps clear explanation thanks for sharing
    anyone want to learn advance devops tools or devops online training visit:
    DevOps Online Training
    DevOps Training institute in Hyderabad
    DevOps Training in Ameerpet

    ReplyDelete
  36. Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.
    dining room interior designer in noida

    ReplyDelete
  37. nice work keep it up thanks for sharing the knowledge.Thanks for sharing this type of information, it is so useful.
    tile bonder manufacturer in delhi

    ReplyDelete
  38. Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.
    Home Decor Wall Lights in delhi

    ReplyDelete

  39. Nice information.. Thanks for sharing this blog. see my website also
    .. VIEW MORE:- Website Designing Company in Delhi

    ReplyDelete
  40. It's A Great Pleasure reading your Article, learned a lot of new things, we have to keep on updating it Mini Militia Pro Pack Hack Apk, Mini Militia hack Version Thanks for posting.

    ReplyDelete
  41. Trialix Male Enhancement Cannabidiol (CBD) is taken from the bud and flower of the cannabis plant. The size of this import trade is without doubt one of the major catalysts for hemp legalization in the U.S. As a renewable supply of a variety of products, hemp gives an thrilling new step in American agriculture. Primarily based on the Marijuana Business Daily, the market 12 months 2016 to 2017 noticed a a hundred and forty percent enhance in licensed areas throughout all the top 10 states that plant hemp. Throughout one research, sixteen contributors that had chemo therapy used a CBD-THC mixture. In short, Cannabidiol - or CBD - is a hashish compound that has many therapeutic advantages. Extra cures for pain relief embody massage, chiropractic care, Reiki and power remedy, acupuncture and medical marijuana. Cannabidiol —CBD— is a compound in Hashish that has medical results however doesn't make folks feel stoned” and really counters among the results of THC. It promotes its merchandise as a safer alternative to risky opioids for pain management. Since CBD Oil from the Hemp plant does not include unlawful measures of THC, it is authentic in each one of the 50 states. Listed here are seven health advantages of CBD oil which can be backed by scientific proof. The hemp is specifically chosen for top terpene and CBD content for a more effective product.
    https://www.smore.com/czbha-trialix-male-enhancement-canada

    ReplyDelete
  42. InstaaCoders Technologies pvt. Ltd providing web design in Los Angeles,Website Development Company Los Angeles, Mobile App Development Company in Delhi services to companies and startups from Canada and USA.
    web design company los angeles ca
    Website Development Company Los Angeles
    Mobile App Development Company in Delhi
    Mobile App Development Services in Delhi


    ReplyDelete
  43. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.

    Telephony System
    Mobile Device
    ted

    ReplyDelete
  44. Thanks, you guys that is a great explanation. keep up the good work in your granite blog.
    Mobile app Development Company in Noida

    ReplyDelete
  45. Excellent blog I visit this blog it's really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative.
    Workday HCM Online Training!
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  46. Excellent blog I visit this blog it's really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative.
    Workday HCM Online Training!
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  47. Great post and informative blog.it was awesome to read, thanks for sharing this great content to my vision.

    CEH Training In Hyderbad

    ReplyDelete
  48. Excellent blog I visit this blog it's really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative.
    Workday HCM Online Training!
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  49. Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
    Thanks & Regards,
    VRIT Professionals,
    No.1 Leading Web Designing Training Institute In Chennai.

    And also those who are looking for
    Web Designing Training Institute in Chennai
    SEO Training Institute in Chennai
    Photoshop Training Institute in Chennai
    PHP & Mysql Training Institute in Chennai
    Android Training Institute in Chennai

    ReplyDelete
  50. The blog was absolutely fantastic! Lot of information is helpful in some or the other way. Keep updating the blog, looking forward for more content...Great job, keep it up
    Workday HCM Online Training
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  51. The blog was absolutely fantastic! Lot of information is helpful in some or the other way. Keep updating the blog, looking forward for more content...Great job, keep it up
    Workday HCM Online Training
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  52. Amazing web journal I visit this blog it's extremely marvelous. Interestingly, in this blog content composed plainly and reasonable. The substance of data is educational.
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  53. I feel happy about and learning more about this topic. keep sharing your information regularly for my future reference. This content creates new hope and inspiration within me. Thanks for sharing an article like this. the information which you have provided is better than another blog.
    Best IELTS Coaching institute in Dwarka

    ReplyDelete
  54. Amazing web journal I visit this blog it's extremely marvelous. Interestingly, in this blog content composed plainly and reasonable. The substance of data is educational.
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  55. Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
    it job support

    ReplyDelete
  56. Excellent blog I visit this blog it's really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative.
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  57. An amazing web journal I visit this blog, it's unbelievably wonderful. Oddly, in this blog's content made without a doubt and reasonable. The substance of data is informative.
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training
    oracle Fusion Technical online training

    ReplyDelete
  58. An astounding web diary I visit this blog, it's inconceivably magnificent. Strangely, in this current blog's substance made point of fact and sensible. The substance of information is instructive.
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  59. legends keto
    thus developing you felt excellent overall. Furthermore, genuine pure whey protein proteins necessary proteins is also said to enhance your immune operate and aid in the cope with melanoma. Bearing all these benefits in ideas, and with the valuable connection between genuine pure whey protein proteins necessary proteins and weight-loss, there really is no basis for you to continue doubting the importance
    https://newsletterforhealth.com/legends-keto/

    ReplyDelete
  60. Nice blog, keep more updates about this type of information. Visit for the best Website Designing and Development Company in Delhi.
    Website Designing Company in Delhi

    ReplyDelete
  61. A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  62. A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  63. power testo blast
    he realized that there was no quick solution to her weight-loss concerns. She would have to re-arrange her lifestyle so that she adhered to the appropriate principles of nutrition, cardiovascular, and bodyweight training execute out. Now come Apr Fool's Day she had losing 20 bodyweight. ad clients that were extremely satisfied with their own health and fitness and health and health and fitness and health and health and fitness outcomes. S
    https://newsletterforhealth.com/power-testo-blast/

    ReplyDelete
  64. Joint FLX occurring. Low serum ironIron lack of occasionally produces thinning locks. Some people do not have enough steel in their diets or may not fully absorb steel in their diets. Ladies have heavy menstrual periods may develop a lack of steel. Low steel can be detected by laboratory tests and can be corrected and break off as
    https://www.supplementexamine.com/Joint-FLX/

    ReplyDelete
  65. An astounding web diary I visit this blog, it's inconceivably magnificent. Strangely, in this current blog's substance made point of fact and sensible. The substance of information is instructive.
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  66. keto hack operating to get rid of fat and keep it off. Even weighing in once a 7 times can bring with it advantages. Weighing yourself on a consistent base can allow you to basically notice when bodyweight becomes creeping up. When you notice this, existing measures to avoid further excess bodyweight. avings later in the day, especially if you choose consistent base decrease undesirable
    https://newsletterforhealth.com/keto-hack-diet/

    ReplyDelete
  67. Multi-monitor support: this kind of aspect makes it possible to raise your productivity by changing your monitor setup to your work style. You possibly can make customer list on a single screen and build invoices on other. QuickBooks Customer Service Number You'll be able to put profit insights together from 1 or more monitors. You may also open one companies file on another company’s monitor.
    Makes Enhanced inventory reports: You could make most of the inventory reports in a fashion you prefer.

    ReplyDelete
  68. A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete







  69. A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  70. Get Mutual Fund Investment Schemes by Mutual Fund Wala and know about the best investment platform for you, to get profit.
    Mutual Fund Advisor

    ReplyDelete
  71. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  72. testo drive 365 • It is significant to know that the activity of weight-loss items is directly dependent on several aspects like age, our health and fitness and health, genetics, sex and execute out. Therefore, for maximum impact, patients must seek the guidance of a health good proper care professional before choosing the
    https://newsletterforhealth.com/testo-drive-365-canada/

    ReplyDelete
  73. cerisea medica
    said the jokes on you. This year, Jean hired training instructor who was knowledgeable and had clients that were extremely satisfied with their own health and fitness and health and health and fitness and health and health and fitness outcomes. She realized that there was no quick solution to her weight-loss
    https://newsletterforhealth.com/cerisea-medica/

    ReplyDelete
  74. enhanced keto If this is done for an extended period of time lengthy lasting thinning locks might result. This is known as Traction Hair loss and is not unusual among those who braid or weave their locks. Make sure the person applying the braids or weave is certified to do so and don't wear braids or weaves continuously for cted or the braids are wrapped too restricted , they put a continuing strain on the locks sequence.
    https://newsletterforhealth.com/enhanced-keto/

    ReplyDelete
  75. maxx power libido
    testosterone production. Sex androgenic hormonal or testosterone are very necessary for achieving firmer and fuller growth. Males will fight achieve full sex-related confidence if they encounter from low androgenic hormonal or androgenic hormonal or testosterone. You will not be able to carry out better in
    https://newsletterforhealth.com/maxx-power-libido/

    ReplyDelete