After looking into it I was surprised to learn that there's no built-in way to underline text in a UI element on iPhone - you have to simply draw it yourself.
Searching the web I found some sample code in varying states of usability. By sticking these together and putting a couple more features in I came up with CVUnderlineButton.
It's available on GitHub at https://github.com/benvium/BVUnderlineButton
Simple example button
Here's the README for the control.
BVUnderlineButton
Simple UIButton subclass that draws a button with the title underlined.
Based on code originally found at http://davidjhinson.wordpress.com/2009/11/26/underline-text-on-the-iphone/ with all the fixes from the comments and some further tweaks.
This code requires ARC.
Usage
Add BVUnderlineButton.m and BVUnderlineButton.h to your project.
If you're using a Storyboard or XIB files:
- drag a UIButton to your stage, set the 'Type' (under Attributes Inspector / Button) to Custom
- Set the Class (under Identity Inspector / Custom Class) to BVUnderlineButton.
If you're using code, just create the button as you would a regular Custom style UIButton, e.g.
#import "BVUnderlineButton.h"
BVUnderlineButton *button = [BVUnderlineButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"underlined" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
Adjusting the underline position
Depending on the font you may wish to adjust the vertical position of the underline using the underlinePosition property. The default is -2 pixels.
If you're using a Storyboard or XIB files:
- Select the BVUnderlineButton instance on your stage.
- Open the 'Identity Inspector' and click the + under 'User Defined Runtime Attributes'
- Type 'underlinePosition' for keyPath, choose 'Number' for type, and type in the new value as a floating-point number (e.g. 1)
If you're using code, just set the underlinePosition property.
button.underlinePosition = 1;
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.Block Chain Training in annanagar
ReplyDeleteBlock Chain Training in pune
Block Chain Training in velachery
This comment has been removed by the author.
ReplyDeleteWow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
ReplyDeleterpa training in chennai | best rpa training in chennai | rpa training in chennai | rpa training in bangalore
rpa training in pune | rpa online training
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
ReplyDeleteData Science training in kalyan nagar | Data Science training in OMR
Data Science training in chennai | Data science training in velachery
Data science training in tambaram | Data science training in jaya nagar
I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
ReplyDeletejava training in chennai | java training in bangalore
java online training | java training in pune
I have been meaning to write something like this on my website and you have given me an idea. Cheers.
ReplyDeleteonline Python certification course
python training in OMR
python training course in chennai
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
ReplyDeleteDevops interview questions and answers
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
ReplyDeleteOracle Fusion HCM Online Training
Oracle Fusion SCM Online Training
Susunan kartu murni besar Susunan kartu dengan nilai paling sedikit 39 bulatan Susunan kartu murni kecil Susunan kartu dengan nilai paling banyak 9 bulatan Susunan kartu 6 dewa
ReplyDeleteasikqq
dewaqq
sumoqq
interqq
pionpoker
bandar ceme terpercaya
hobiqq
paito warna terlengkap
bocoran sgp
gta san andreas apk
ReplyDeleteThanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website all123movies.pictures
ReplyDeleteuntold real horror story in hindi
ReplyDeleteWe strive to provide our candidates with excellent care
Plumbing & HVAC Services San Diego
ReplyDeleteAir Star Heating guarantees reliability and quality for all equipment and services.
Air Star Heating is specializing in providing top-quality heating, ventilating, air conditioning, and plumbing services to our customers and clients.
Our company is leading the market right now. By using our seamless and huge array of services. Our customers can now have the privilege of taking benefit from our services very easily and swiftly. To cope up with the desires and needs of our clients we have built an excellent reputation. We are already having a huge list of satisfied customers that seem to be very pleased with our services.
Plumbing & HVAC Services in San Diego. Call now (858) 900-9977 ✓Licensed & Insured ✓Certified Experts ✓Same Day Appointment ✓Original Parts Only ✓Warranty On Every Job.
Visit:- https://airstarheating.com
nice post
ReplyDeleteMontessori Training Institute Near Me | Montessori Course in Urapakkam
ReplyDeleteHi.
The blog is fantastic, offering incredible and highly informative content that engages learners and enhances their knowledge. It encourages readers to explore the subject deeply and become involved in the learning process. I look forward to more such valuable content in the future. Here is sharing some Mulesoft Training information may be its helpful to you.
Mulesoft Training
Your writing style is so engaging and enjoyable. It feels like I'm having a conversation with a knowledgeable friend. Kudos
ReplyDeletecheck our digital marketing program
digital marketing institute in coimbatore with paid internship