omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Custom views with bold text and rounded corners

    Pythonista
    3
    14
    2154
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp @peiriannydd last edited by

      @peiriannydd Finally, you didn't say if this solved your two problems...

      1 Reply Last reply Reply Quote 0
      • peiriannydd
        peiriannydd last edited by

        Yes, thank you, this solved my problems, although using a label since <system-bold> doesn’t work with ui.draw_string seems like a bug workaround.

        cvp 3 Replies Last reply Reply Quote 0
        • cvp
          cvp @peiriannydd last edited by cvp

          @peiriannydd Said

          seems like a bug workaround.

          Sure, but what else to do if the app is no more updated?

          1 Reply Last reply Reply Quote 0
          • cvp
            cvp @peiriannydd last edited by

            @peiriannydd other workaround

            		f = '<System>'
            		ui.draw_string(self.text,(0,0,self.width,self.height), (f,20), 'black',ui.ALIGN_CENTER)
            		ui.draw_string(self.text,(1,1,self.width-1,self.height-1), (f,20), 'black',ui.ALIGN_CENTER)
            
            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by

              So, a way that should work would be to use UIFont to find the system font name, and then create a bold version, then find the name of that... Just an idea, have not pursued it yet

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @JonB last edited by cvp

                @JonB I did try:

                <UICTFont: 0x103990c70> font-family: ".SFUI-Semibold"; font-weight: bold; font-style: normal; font-size: 20.00pt
                
                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB last edited by JonB

                  Try

                  ".SFCompactText-Bold"
                  

                  Or

                  ".SFProText-Bold"
                  

                  Also-- the "Text" part of the name can be replaced with Rounded, or Display. Apparently Text is supposed to used under 19pt, Display for 20pt+. I'm not sure what Rounded is for -- looks a little more informal.

                  I think apple tried to obfuscate system font names so people used their new API in iOS13, to prevent people hard coding fonts that might change later. Hence reason that .SFUI doesnt work

                  I assume draw_string is using UIFont.fontWithName_size_

                  cvp 1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB last edited by

                    I think compact is for watchOS, Pro for iOS.

                    Does UIFont have a .fontName() method?

                    cvp 1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @JonB last edited by cvp

                      @JonB neither ".SFProText-Bold" nor ".SFProDisplay-Bold" do work

                      I ask me if for SF standard system font, bold in name does work without a supplementary bold attribute

                      1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @JonB last edited by cvp

                        @JonB said

                        does UIFont have a .fontName() method?

                        Yes

                        1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @peiriannydd last edited by cvp

                          @peiriannydd this works, in place of ui.draw_string

                          		UIFont = ObjCClass('UIFont').boldSystemFontOfSize_(20.0)		
                          		attrtext = ObjCClass('NSMutableAttributedString').alloc().initWithString_(ns(self.text))
                          		attrtext.addAttribute_value_range_(ns('NSFont'), UIFont, NSRange(0,len(self.text)))		
                          		attrtext.drawInRect_(CGRect(CGPoint(0, 0), CGSize(self.width, self.height)))
                          

                          Nb: needs

                          from objc_util import *
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors