I have a UIActionSheet with title string "DO: These tasks". In the title string, the substring "DO:" should be Bold(with a particular font size) and the substring "These tasks" should be Regular. Is it possible? How can I do this?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
For iOS 7 the following code will work.
Implement
UIActionSheetDelegate
as followsFor iOS 6
Following may be useful.
I assume you have a class which implements the
UIActionSheetDelegate
protocol and your class is a delegate class of the currentUIActionSheet
, so in that class you can change the whole title of theUIActionSheet
likebut as far as you see you have no chance to format the part of the
UILabel
object'stext
property.you could add a new
UILabel
for youractionsheet
now with a different font, if you want to see a text with the boldedDO:
string... but from here the limit is you imagination only, you can format theUIActionSheet
's elements in this method or inside the-didPresentActionSheet:
method as well.so this would be the idea for this.
UPDATE on 7 Oct 2013
in iOS7 we don't really have direct access to the subviews of an
UIAlertView
or anUIActionSheet
object, so this solution might not be working properly on iOS7 environment.if you have any issue with it on iOS7, please comment it to me! thank you.
UPDATE on 22 Jun 2014
I have not found any solution to do such thing directly with the new
UIAlertController
in iOS8, the title label looks to be not visible in the entire view-hierarchy of theUIAlertController
, neither visible before it appears or even after.NOTE: I've also figured out that it is not forbidden to overlap/cover its content, after it appeared on the screen. currently it is impossible to predict that it will work over Beta or whether or not it is AppStore-safe.
NOTE: please bear in your mind the view-lifecycle's schedule, and do not try to present any content in a view or view controler if that is not in the navigation stack already.
anyway, here is a Swift solution how I could reach the layers and I could add my custom view to it.
NOTE: it might be useful to add custom content to an alert/actionsheet, but if it does not work in the future, I will update my answer.
There is an internal property of
UIActionSheet
called_titleLabel
so it is possible to get a reference and change the attributed string property of this label directly.Please be aware, that this is a private API in might be rejected in the App store.
Here is how it works:
see these link .and use it. ohattributedlabel
http://www.cocoacontrols.com/platforms/ios/controls/ohattributedlabel
Based on Holex's answer:
for both iOS7 and iOS6 the following has worked for me to change the title of UIActionSheet properties. Please note that I am actually adding a new subview, since for unknown? reason updating the current UILabel gives only vertically half of the text? Also "title" is apparantly the first UILabel, so we break the loop after one change.
The above seems to work on iOS6 and iOS7 simulators. I am not sure if this would work with other future versions of iOS though.