3

So I have an app where content appears in a textview. I am using attributed strings as some part of text contains links to websites. The problem is the content font size. It is too small in iPads. It seems fine in iPhones. Below is the code I am using.

 let attributedString = NSMutableAttributedString(string: "About\n      The Common Room Virtual Fireplace App was designed with love by 5x entrepreneur, Arjun Rai. The goal of this is to create the ultimate mobile and relaxing ambience anywhere and anytime. Rai’s passion for fireplaces along with minimalism in art has led him to build several apps and startups over the years since he was a teenager. Common Room is yet another effort to bringing beautiful experiences to everyone...just a bit more relaxing this time around. :) Follow him at twitter.com/arjunraime")


    attributedString.addAttribute(NSLinkAttributeName, value: "http://arjunrai.me/", range: NSRange(location: 92, length: 10))

    attributedString.addAttribute(NSLinkAttributeName, value: "https://itunes.apple.com/in/genre/ios/id36?mt=8", range: NSRange(location: 14, length: 33))

    attributedString.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-UltraLight", size: 12.0)!, range: NSRange(location: 0, length: 506))

    attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.white, range: NSRange(location: 0, length: 506))

    attributedString.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-Medium",size: 12.0)!, range:NSRange(location: 0, length: 5))

    attributedString.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-Medium",size: 12.0)!, range:NSRange(location: 15, length: 33))

    attributedString.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-Medium",size: 12.0)!, range:NSRange(location: 92, length: 11))

    attributedString.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-Medium",size: 12.0)!, range:NSRange(location: 470, length: 36))

    attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraph, range: NSRange(location: 0, length: 506))

    infoTextview.attributedText = attributedString

    /*************************how it works****************/

    let attributedString1 = NSMutableAttributedString(string: "How it Works?\n       Common Room works alongside any of your favorite music apps. Simply start Common Room app first followed by opening your favorite music app to play songs then return back. You can control the volume of the fire crackle as well as turn it on and off via the menu in Common Room. Enjoy!")

    attributedString1.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-UltraLight", size: 12.0)!, range: NSRange(location: 0, length: 305))

    attributedString1.addAttribute(NSForegroundColorAttributeName, value: UIColor.white, range: NSRange(location: 0, length: 305))

    attributedString1.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-Medium",size: 12.0)!, range:NSRange(location: 0, length: 13))

    attributedString1.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-Medium",size: 12.0)!, range:NSRange(location: 60, length: 21))

    attributedString1.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-Medium",size: 12.0)!, range:NSRange(location: 231, length: 9))

    attributedString1.addAttribute(NSFontAttributeName, value: UIFont(name: "AvenirNext-Medium",size: 12.0)!, range:NSRange(location: 258, length: 12))


    attributedString1.addAttribute(NSParagraphStyleAttributeName, value: paragraph, range: NSRange(location: 0, length: 305))


    infoTextview1.attributedText = attributedString1

Is there any way of making the text scale automatically based on screen size? Is adaptive sizing the only way becuase that did not make any visible difference in the output.

Please see the different outputs for the current code.

iPad screen output

iPad screen

iPhone screen output

iPhone screen

Can someone let me know how to do this?

BizDev
  • 371
  • 1
  • 4
  • 21
  • 1
    Just set `adjustsFontSizeToFitWidth` to `YES`. Here is the documentation link https://developer.apple.com/reference/uikit/uilabel – arunjos007 Apr 07 '17 at 08:12
  • @arunjos007 Hi thanks for the reply. I tried and it shows UItextview has no member adjustsFontSizeToFitWidth. Any idea? – BizDev Apr 07 '17 at 08:19
  • Oh Sorry, its for UILabel. – arunjos007 Apr 07 '17 at 08:30
  • For text fileds take a look at this StackOverflow question http://stackoverflow.com/questions/28924836/different-font-size-for-different-devices-in-xcode-6 – arunjos007 Apr 07 '17 at 08:32
  • The iPad screenshot looks zoomed out to me. Are you it's set to 100%? – Code Different Apr 07 '17 at 11:47
  • @CodeDifferent No we reduced the scale. However that was simulator screenshot. In a real device the font looks way too smaller than in an iPhone. – BizDev Apr 07 '17 at 12:07

0 Answers0