How to do custom font and color in UITableViewRowAction without StoryboardSwipe to Delete and the “More” button (like in Mail app on iOS 7)How to change UITableViewRowAction title color?UITableViewRowAction customise title font size in SwiftCan I embed a custom font in an iPhone application?Need to fire didSelectRowAtIndexPath from within a UITextField in custom cellUITableView - how to recognize a cancel deletion?How to detect tableView cell touched or clicked in swiftremove the delete button ⛔️ on table rows in edit modeHow to implement multiple custom cells with willDisplayCell method?Expand and Collapse tableview cellsTableView not displaying text with JSON data from API callHow to set custom UITableViewRowAction depending on IndexPath.row?How to set the action of UITableViewRowAction
Show two plots together: a two dimensional curve tangent to the maxima of a three dimensional plot
What allows us to use imaginary numbers?
Does git delete empty folders?
From France west coast to Portugal via ship?
How do we test and determine if a USB cable+connector is version 2, 3.0 or 3.1?
How to detect a failed AES256 decryption programmatically?
Tabularx with hline and overrightarrow vertical spacing
Is "stainless" a bulk or a surface property of stainless steel?
Angles between vectors of center of two incircles
Is there a commercial liquid with refractive index greater than n=2?
Starships without computers?
Check disk usage of files returned with spaces
What causes burn marks on the air handler in the attic?
Unsolved Problems due to Lack of Computational Power
Installing certbot - error - "nothing provides pyparsing"
Have made several mistakes during the course of my PhD. Can't help but feel resentment. Can I get some advice about how to move forward?
Installing the original OS X version onto a Mac?
Why don't politicians push for fossil fuel reduction by pointing out their scarcity?
Which basis does the wavefunction collapse to?
Is there a way to make the "o" keypress of other-window <C-x><C-o> repeatable?
Just one file echoed from an array of files
How to translate 脑袋短路 into English?
Rotate List by K places
Virtual destructor moves object out of rodata section
How to do custom font and color in UITableViewRowAction without Storyboard
Swipe to Delete and the “More” button (like in Mail app on iOS 7)How to change UITableViewRowAction title color?UITableViewRowAction customise title font size in SwiftCan I embed a custom font in an iPhone application?Need to fire didSelectRowAtIndexPath from within a UITextField in custom cellUITableView - how to recognize a cancel deletion?How to detect tableView cell touched or clicked in swiftremove the delete button ⛔️ on table rows in edit modeHow to implement multiple custom cells with willDisplayCell method?Expand and Collapse tableview cellsTableView not displaying text with JSON data from API callHow to set custom UITableViewRowAction depending on IndexPath.row?How to set the action of UITableViewRowAction
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have classic TableView where you can delete item if you swipe and than clicking on the button. I know how to set custom background on the cell, but I can't find how I can set custom font and color for that.
Thank you for help!
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?
var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default,
title: "Delete",
handler:
(action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
println("Delete button clicked!")
)
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction]
ios iphone uitableview swift uitableviewrowaction
add a comment |
I have classic TableView where you can delete item if you swipe and than clicking on the button. I know how to set custom background on the cell, but I can't find how I can set custom font and color for that.
Thank you for help!
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?
var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default,
title: "Delete",
handler:
(action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
println("Delete button clicked!")
)
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction]
ios iphone uitableview swift uitableviewrowaction
Check my answer on this post: stackoverflow.com/a/36145706/2734651
– Lee Andrew
Mar 22 '16 at 3:41
add a comment |
I have classic TableView where you can delete item if you swipe and than clicking on the button. I know how to set custom background on the cell, but I can't find how I can set custom font and color for that.
Thank you for help!
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?
var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default,
title: "Delete",
handler:
(action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
println("Delete button clicked!")
)
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction]
ios iphone uitableview swift uitableviewrowaction
I have classic TableView where you can delete item if you swipe and than clicking on the button. I know how to set custom background on the cell, but I can't find how I can set custom font and color for that.
Thank you for help!
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?
var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default,
title: "Delete",
handler:
(action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
println("Delete button clicked!")
)
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction]
ios iphone uitableview swift uitableviewrowaction
ios iphone uitableview swift uitableviewrowaction
edited Jan 2 '16 at 12:49
ipinak
2,8081 gold badge15 silver badges32 bronze badges
2,8081 gold badge15 silver badges32 bronze badges
asked Mar 14 '15 at 13:11
Vlastimil FiserVlastimil Fiser
871 gold badge2 silver badges9 bronze badges
871 gold badge2 silver badges9 bronze badges
Check my answer on this post: stackoverflow.com/a/36145706/2734651
– Lee Andrew
Mar 22 '16 at 3:41
add a comment |
Check my answer on this post: stackoverflow.com/a/36145706/2734651
– Lee Andrew
Mar 22 '16 at 3:41
Check my answer on this post: stackoverflow.com/a/36145706/2734651
– Lee Andrew
Mar 22 '16 at 3:41
Check my answer on this post: stackoverflow.com/a/36145706/2734651
– Lee Andrew
Mar 22 '16 at 3:41
add a comment |
9 Answers
9
active
oldest
votes
How to use a custom font?
It's pretty easy.
- Firstly, you need to include your custom font files to your project.
- Next, go to your info.plist file and add a new entry with the key "Fonts provided by application". Note that this entry should be an Array.
- Then add the names of these files as elements of this array.
And that's it! All you need then is to use the font by its name like this
cell.textLabel.font = [UIFont fontWithName:@"FontName" size:16];
How to change the font color?
Even easier. All you need is
cell.textlabel.textcolor = UIColor.redColor()
Edit:
In your case you want to change the font of the RowAction. So I think of only 2 solutions. One to use [UIColor colorWithPatterImage:]
Or you can user [[UIButton appearance] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
because the RowAction contains a button.
Thank you, but this is not the right answer what I need. You help me implement custom font, that I know. I need set color/font for the cell in UITableViewActionRow. (the pink here: https://www.dropbox.com/s/jaineb3qgcezm90/Screenshot%202015-03-15%2009.14.51.png?dl=0) The code what you wrote me not working, because in the action what you can see in my first post here, you can work just with "title" but the title is reserved for localization only. Any idea how to fix it?
– Vlastimil Fiser
Mar 15 '15 at 2:20
I have edited my answer. Sorry, my bad! :)
– Ashraf Tawfeeq
Mar 15 '15 at 7:08
1
OMG! You made my day buddy! Thanks. I just rewrote your code to the Swift version and all working perfectly.UIButton.appearance().setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
EDIT: And do you know, how I set the custom font for the button? I can't find function like "setTitleFont" there.
– Vlastimil Fiser
Mar 15 '15 at 7:14
I guess something like the following:NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"YOURFONT" size:14], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil]; [[UIButton appearance] setTitleTextAttributes:attributes];
– Ashraf Tawfeeq
Mar 15 '15 at 7:20
1
I can't usesetValueForKeyPath
on the button, it works for you?.... I'm trying something like thisUIButton.appearance().titleLabel?.font = UIFont(name: "Futura", size: 40)
but still not working, is it without error, but the size and font is still on default.
– Vlastimil Fiser
Mar 15 '15 at 13:01
|
show 10 more comments
Well, the only way I've found to set a custom font is to use the appearanceWhenContainedIn
method of the UIAppearance
protocol. This method isn't yet available in Swift, so you have to do it in Objective-C.
I made a class method in a utility Objective-C class to set it up:
+ (void)setUpDeleteRowActionStyleForUserCell
UIFont *font = [UIFont fontWithName:@"AvenirNext-Regular" size:19];
NSDictionary *attributes = @NSFontAttributeName: font,
NSForegroundColorAttributeName: [UIColor whiteColor];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString: @"DELETE"
attributes: attributes];
/*
* We include UIView in the containment hierarchy because there is another button in UserCell that is a direct descendant of UserCell that we don't want this to affect.
*/
[[UIButton appearanceWhenContainedIn:[UIView class], [UserCell class], nil] setAttributedTitle: attributedTitle
forState: UIControlStateNormal];
This works, but it's definitely not ideal. If you don't include UIView in the containment hierarchy, then it ends up affecting the disclosure indicator as well (I didn't even realize the disclosure indicator was a UIButton subclass). Also, if you have a UIButton in your cell that is inside a subview in the cell, then that button will get affected by this solution as well.
Considering the complications, it might be better to just use one of the more customizable open source libraries out there for table cell swipe options.
4
I have figured out an improvement on this answer to avoid affecting other buttons inside the cell. After inspecting the view hierarchy of an expanded cell, I found that the delete button is sitting inside aUITableViewCellDeleteConfirmationView
view. This is a private API but using this instead ofUIView
targets only the delete button and not any other button in the cell. So instead of[UIView class]
, use[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]
– Dima
May 13 '15 at 23:50
@Dima Can you confirm if your app passed the review, or they rejected it because you used the private API?
– Septronic
Jan 2 '16 at 11:09
This was a while ago and my app has passed several reviews without a problem.
– Dima
Jan 4 '16 at 22:07
How to add more buttons in this way?
– guhan0
Jul 10 '17 at 12:38
After doing agrep
following this nshipster.com/uiappearance, doesn't seem thatsetAttributedTitle:forState:
is available forUIButton
customization. Can you confirm that this answer still works?
– valcanaia
Mar 18 at 12:01
add a comment |
I want to share my solution for ObjC, this is just a trick but works as expected for me.
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
// this just convert view to `UIImage`
UIImage *(^imageWithView)(UIView *) = ^(UIView *view)
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
;
// This is where the magic happen,
// The width and height must be dynamic (it's up to you how to implement it)
// to keep the alignment of the label in place
//
UIColor *(^getColorWithLabelText)(NSString*, UIColor*, UIColor*) = ^(NSString *text, UIColor *textColor, UIColor *bgColor)
UILabel *lbDelete = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 47, 40)];
lbDelete.font = [UIFont boldSystemFontOfSize:11];
lbDelete.text = text;
lbDelete.textAlignment = NSTextAlignmentCenter;
lbDelete.textColor = textColor;
lbDelete.backgroundColor = bgColor;
return [UIColor colorWithPatternImage:imageWithView(lbDelete)];
;
// The `title` which is `@" "` is important it
// gives you the space you needed for the
// custom label `47[estimated width], 40[cell height]` on this example
//
UITableViewRowAction *btDelete;
btDelete = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"Delete");
[tableView setEditing:NO];
];
// Implementation
//
btDelete.backgroundColor = getColorWithLabelText(@"Delete", [UIColor whiteColor], [YJColor colorWithHexString:@"fe0a09"]);
UITableViewRowAction *btMore;
btMore = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleNormal
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"More");
[tableView setEditing:NO];
];
// Implementation
//
btMore.backgroundColor = getColorWithLabelText(@"More", [UIColor darkGrayColor], [YJColor colorWithHexString:@"46aae8"]);
return @[btMore, btDelete];
[YJColor colorWithHexString:<NSString>];
is just to convert hex string to UIColor.
Check the example output screenshot.
add a comment |
If you use XCode's Debug View Hierarchy to look what is happening in UITableView when the swipe buttons are active, you'll see that UITableViewRowAction items translates to button called _UITableViewCellActionButton
, contained in UITableViewCellDeleteConfirmationView
. One way to change button's properties is to intercept it when it's added to UITableViewCell
. In your UITableViewCell
derived class write something like this:
private let buttonFont = UIFont.boldSystemFontOfSize(13)
private let confirmationClass: AnyClass = NSClassFromString("UITableViewCellDeleteConfirmationView")!
override func addSubview(view: UIView)
super.addSubview(view)
// replace default font in swipe buttons
let s = subviews.flatMap($0).filter $0.isKindOfClass(confirmationClass)
for sub in s
for button in sub.subviews
if let b = button as? UIButton
b.titleLabel?.font = buttonFont
1
Just a note: This uses a private API. It may get rejected, or you may have luck.
– Frederik A. Winkelsdorf
Apr 24 '16 at 16:27
Don't know if this changed for iOS 11 or did in 10... but it looks like that's no longer the class getting added. In Xcode 9 I'm seeing a UISwipeActionStandardButton. As is with attempting to use Private API stuff, the min Apple changes it, your stuff no longer works.
– jhelzer
Jun 24 '17 at 0:35
add a comment |
This seems to work, at least for setting the font color:
- (void)setupRowActionStyleForTableViewSwipes
UIButton *appearanceButton = [UIButton appearanceWhenContainedInInstancesOfClasses:@[[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]]];
[appearanceButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
add a comment |
You could use UIButton.appearance
to style the button inside the row action. Like so:
let buttonStyle = UIButton.appearance(whenContainedInInstancesOf: [YourViewController.self])
let font = UIFont(name: "Custom-Font-Name", size: 16.0)!
let string = NSAttributedString(string: "BUTTON TITLE", attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.foregroundColor : UIColor.green])
buttonStyle.setAttributedTitle(string, for: .normal)
Note: this will affect all of your buttons in this view controller.
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.
– Dwhitz
Mar 27 at 14:17
add a comment |
Here is some Swift Code that might be helpful:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) ->[AnyObject]?
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
UIButton.appearance().setAttributedTitle(NSAttributedString(string: "Your Button", attributes: attributes), forState: .Normal)
// Things you do...
This will manipulate all buttons in your application.
4
Actually this will manipulate ALL buttons throughout your application. It appears that after this code is executed all buttons in the application are affected by this code. Not an ideal solution unless you don't have any other buttons in your application, which is probably not the case.
– northdig
Aug 12 '15 at 22:20
i edited my last line to correct my post
– alexdd55
Aug 13 '15 at 9:05
add a comment |
I think you can use this method to change the appearance only in one (or more, you can define it) viewcontrollers:
//create your attributes however you want to
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
//Add more view controller types in the []
UIButton.appearanceWhenContainedInInstancesOfClasses([ViewController.self])
Hope this helped.
add a comment |
//The following code is in Swift3.1
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
let rejectAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2715nReject") action, indexPath in
print("didtapReject")
rejectAction.backgroundColor = UIColor.gray
let approveAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2713nApprove") action, indexPath in
print("didtapApprove")
approveAction.backgroundColor = UIColor.orange
return [rejectAction, approveAction]
This doesn't seem to change the font color at all.
– Travis M.
Aug 23 '17 at 18:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29049318%2fhow-to-do-custom-font-and-color-in-uitableviewrowaction-without-storyboard%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
How to use a custom font?
It's pretty easy.
- Firstly, you need to include your custom font files to your project.
- Next, go to your info.plist file and add a new entry with the key "Fonts provided by application". Note that this entry should be an Array.
- Then add the names of these files as elements of this array.
And that's it! All you need then is to use the font by its name like this
cell.textLabel.font = [UIFont fontWithName:@"FontName" size:16];
How to change the font color?
Even easier. All you need is
cell.textlabel.textcolor = UIColor.redColor()
Edit:
In your case you want to change the font of the RowAction. So I think of only 2 solutions. One to use [UIColor colorWithPatterImage:]
Or you can user [[UIButton appearance] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
because the RowAction contains a button.
Thank you, but this is not the right answer what I need. You help me implement custom font, that I know. I need set color/font for the cell in UITableViewActionRow. (the pink here: https://www.dropbox.com/s/jaineb3qgcezm90/Screenshot%202015-03-15%2009.14.51.png?dl=0) The code what you wrote me not working, because in the action what you can see in my first post here, you can work just with "title" but the title is reserved for localization only. Any idea how to fix it?
– Vlastimil Fiser
Mar 15 '15 at 2:20
I have edited my answer. Sorry, my bad! :)
– Ashraf Tawfeeq
Mar 15 '15 at 7:08
1
OMG! You made my day buddy! Thanks. I just rewrote your code to the Swift version and all working perfectly.UIButton.appearance().setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
EDIT: And do you know, how I set the custom font for the button? I can't find function like "setTitleFont" there.
– Vlastimil Fiser
Mar 15 '15 at 7:14
I guess something like the following:NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"YOURFONT" size:14], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil]; [[UIButton appearance] setTitleTextAttributes:attributes];
– Ashraf Tawfeeq
Mar 15 '15 at 7:20
1
I can't usesetValueForKeyPath
on the button, it works for you?.... I'm trying something like thisUIButton.appearance().titleLabel?.font = UIFont(name: "Futura", size: 40)
but still not working, is it without error, but the size and font is still on default.
– Vlastimil Fiser
Mar 15 '15 at 13:01
|
show 10 more comments
How to use a custom font?
It's pretty easy.
- Firstly, you need to include your custom font files to your project.
- Next, go to your info.plist file and add a new entry with the key "Fonts provided by application". Note that this entry should be an Array.
- Then add the names of these files as elements of this array.
And that's it! All you need then is to use the font by its name like this
cell.textLabel.font = [UIFont fontWithName:@"FontName" size:16];
How to change the font color?
Even easier. All you need is
cell.textlabel.textcolor = UIColor.redColor()
Edit:
In your case you want to change the font of the RowAction. So I think of only 2 solutions. One to use [UIColor colorWithPatterImage:]
Or you can user [[UIButton appearance] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
because the RowAction contains a button.
Thank you, but this is not the right answer what I need. You help me implement custom font, that I know. I need set color/font for the cell in UITableViewActionRow. (the pink here: https://www.dropbox.com/s/jaineb3qgcezm90/Screenshot%202015-03-15%2009.14.51.png?dl=0) The code what you wrote me not working, because in the action what you can see in my first post here, you can work just with "title" but the title is reserved for localization only. Any idea how to fix it?
– Vlastimil Fiser
Mar 15 '15 at 2:20
I have edited my answer. Sorry, my bad! :)
– Ashraf Tawfeeq
Mar 15 '15 at 7:08
1
OMG! You made my day buddy! Thanks. I just rewrote your code to the Swift version and all working perfectly.UIButton.appearance().setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
EDIT: And do you know, how I set the custom font for the button? I can't find function like "setTitleFont" there.
– Vlastimil Fiser
Mar 15 '15 at 7:14
I guess something like the following:NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"YOURFONT" size:14], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil]; [[UIButton appearance] setTitleTextAttributes:attributes];
– Ashraf Tawfeeq
Mar 15 '15 at 7:20
1
I can't usesetValueForKeyPath
on the button, it works for you?.... I'm trying something like thisUIButton.appearance().titleLabel?.font = UIFont(name: "Futura", size: 40)
but still not working, is it without error, but the size and font is still on default.
– Vlastimil Fiser
Mar 15 '15 at 13:01
|
show 10 more comments
How to use a custom font?
It's pretty easy.
- Firstly, you need to include your custom font files to your project.
- Next, go to your info.plist file and add a new entry with the key "Fonts provided by application". Note that this entry should be an Array.
- Then add the names of these files as elements of this array.
And that's it! All you need then is to use the font by its name like this
cell.textLabel.font = [UIFont fontWithName:@"FontName" size:16];
How to change the font color?
Even easier. All you need is
cell.textlabel.textcolor = UIColor.redColor()
Edit:
In your case you want to change the font of the RowAction. So I think of only 2 solutions. One to use [UIColor colorWithPatterImage:]
Or you can user [[UIButton appearance] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
because the RowAction contains a button.
How to use a custom font?
It's pretty easy.
- Firstly, you need to include your custom font files to your project.
- Next, go to your info.plist file and add a new entry with the key "Fonts provided by application". Note that this entry should be an Array.
- Then add the names of these files as elements of this array.
And that's it! All you need then is to use the font by its name like this
cell.textLabel.font = [UIFont fontWithName:@"FontName" size:16];
How to change the font color?
Even easier. All you need is
cell.textlabel.textcolor = UIColor.redColor()
Edit:
In your case you want to change the font of the RowAction. So I think of only 2 solutions. One to use [UIColor colorWithPatterImage:]
Or you can user [[UIButton appearance] setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
because the RowAction contains a button.
edited Mar 15 '15 at 7:20
answered Mar 14 '15 at 15:39
Ashraf TawfeeqAshraf Tawfeeq
2,7141 gold badge15 silver badges31 bronze badges
2,7141 gold badge15 silver badges31 bronze badges
Thank you, but this is not the right answer what I need. You help me implement custom font, that I know. I need set color/font for the cell in UITableViewActionRow. (the pink here: https://www.dropbox.com/s/jaineb3qgcezm90/Screenshot%202015-03-15%2009.14.51.png?dl=0) The code what you wrote me not working, because in the action what you can see in my first post here, you can work just with "title" but the title is reserved for localization only. Any idea how to fix it?
– Vlastimil Fiser
Mar 15 '15 at 2:20
I have edited my answer. Sorry, my bad! :)
– Ashraf Tawfeeq
Mar 15 '15 at 7:08
1
OMG! You made my day buddy! Thanks. I just rewrote your code to the Swift version and all working perfectly.UIButton.appearance().setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
EDIT: And do you know, how I set the custom font for the button? I can't find function like "setTitleFont" there.
– Vlastimil Fiser
Mar 15 '15 at 7:14
I guess something like the following:NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"YOURFONT" size:14], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil]; [[UIButton appearance] setTitleTextAttributes:attributes];
– Ashraf Tawfeeq
Mar 15 '15 at 7:20
1
I can't usesetValueForKeyPath
on the button, it works for you?.... I'm trying something like thisUIButton.appearance().titleLabel?.font = UIFont(name: "Futura", size: 40)
but still not working, is it without error, but the size and font is still on default.
– Vlastimil Fiser
Mar 15 '15 at 13:01
|
show 10 more comments
Thank you, but this is not the right answer what I need. You help me implement custom font, that I know. I need set color/font for the cell in UITableViewActionRow. (the pink here: https://www.dropbox.com/s/jaineb3qgcezm90/Screenshot%202015-03-15%2009.14.51.png?dl=0) The code what you wrote me not working, because in the action what you can see in my first post here, you can work just with "title" but the title is reserved for localization only. Any idea how to fix it?
– Vlastimil Fiser
Mar 15 '15 at 2:20
I have edited my answer. Sorry, my bad! :)
– Ashraf Tawfeeq
Mar 15 '15 at 7:08
1
OMG! You made my day buddy! Thanks. I just rewrote your code to the Swift version and all working perfectly.UIButton.appearance().setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
EDIT: And do you know, how I set the custom font for the button? I can't find function like "setTitleFont" there.
– Vlastimil Fiser
Mar 15 '15 at 7:14
I guess something like the following:NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"YOURFONT" size:14], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil]; [[UIButton appearance] setTitleTextAttributes:attributes];
– Ashraf Tawfeeq
Mar 15 '15 at 7:20
1
I can't usesetValueForKeyPath
on the button, it works for you?.... I'm trying something like thisUIButton.appearance().titleLabel?.font = UIFont(name: "Futura", size: 40)
but still not working, is it without error, but the size and font is still on default.
– Vlastimil Fiser
Mar 15 '15 at 13:01
Thank you, but this is not the right answer what I need. You help me implement custom font, that I know. I need set color/font for the cell in UITableViewActionRow. (the pink here: https://www.dropbox.com/s/jaineb3qgcezm90/Screenshot%202015-03-15%2009.14.51.png?dl=0) The code what you wrote me not working, because in the action what you can see in my first post here, you can work just with "title" but the title is reserved for localization only. Any idea how to fix it?
– Vlastimil Fiser
Mar 15 '15 at 2:20
Thank you, but this is not the right answer what I need. You help me implement custom font, that I know. I need set color/font for the cell in UITableViewActionRow. (the pink here: https://www.dropbox.com/s/jaineb3qgcezm90/Screenshot%202015-03-15%2009.14.51.png?dl=0) The code what you wrote me not working, because in the action what you can see in my first post here, you can work just with "title" but the title is reserved for localization only. Any idea how to fix it?
– Vlastimil Fiser
Mar 15 '15 at 2:20
I have edited my answer. Sorry, my bad! :)
– Ashraf Tawfeeq
Mar 15 '15 at 7:08
I have edited my answer. Sorry, my bad! :)
– Ashraf Tawfeeq
Mar 15 '15 at 7:08
1
1
OMG! You made my day buddy! Thanks. I just rewrote your code to the Swift version and all working perfectly.
UIButton.appearance().setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
EDIT: And do you know, how I set the custom font for the button? I can't find function like "setTitleFont" there.– Vlastimil Fiser
Mar 15 '15 at 7:14
OMG! You made my day buddy! Thanks. I just rewrote your code to the Swift version and all working perfectly.
UIButton.appearance().setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
EDIT: And do you know, how I set the custom font for the button? I can't find function like "setTitleFont" there.– Vlastimil Fiser
Mar 15 '15 at 7:14
I guess something like the following:
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"YOURFONT" size:14], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil]; [[UIButton appearance] setTitleTextAttributes:attributes];
– Ashraf Tawfeeq
Mar 15 '15 at 7:20
I guess something like the following:
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"YOURFONT" size:14], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil]; [[UIButton appearance] setTitleTextAttributes:attributes];
– Ashraf Tawfeeq
Mar 15 '15 at 7:20
1
1
I can't use
setValueForKeyPath
on the button, it works for you?.... I'm trying something like this UIButton.appearance().titleLabel?.font = UIFont(name: "Futura", size: 40)
but still not working, is it without error, but the size and font is still on default.– Vlastimil Fiser
Mar 15 '15 at 13:01
I can't use
setValueForKeyPath
on the button, it works for you?.... I'm trying something like this UIButton.appearance().titleLabel?.font = UIFont(name: "Futura", size: 40)
but still not working, is it without error, but the size and font is still on default.– Vlastimil Fiser
Mar 15 '15 at 13:01
|
show 10 more comments
Well, the only way I've found to set a custom font is to use the appearanceWhenContainedIn
method of the UIAppearance
protocol. This method isn't yet available in Swift, so you have to do it in Objective-C.
I made a class method in a utility Objective-C class to set it up:
+ (void)setUpDeleteRowActionStyleForUserCell
UIFont *font = [UIFont fontWithName:@"AvenirNext-Regular" size:19];
NSDictionary *attributes = @NSFontAttributeName: font,
NSForegroundColorAttributeName: [UIColor whiteColor];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString: @"DELETE"
attributes: attributes];
/*
* We include UIView in the containment hierarchy because there is another button in UserCell that is a direct descendant of UserCell that we don't want this to affect.
*/
[[UIButton appearanceWhenContainedIn:[UIView class], [UserCell class], nil] setAttributedTitle: attributedTitle
forState: UIControlStateNormal];
This works, but it's definitely not ideal. If you don't include UIView in the containment hierarchy, then it ends up affecting the disclosure indicator as well (I didn't even realize the disclosure indicator was a UIButton subclass). Also, if you have a UIButton in your cell that is inside a subview in the cell, then that button will get affected by this solution as well.
Considering the complications, it might be better to just use one of the more customizable open source libraries out there for table cell swipe options.
4
I have figured out an improvement on this answer to avoid affecting other buttons inside the cell. After inspecting the view hierarchy of an expanded cell, I found that the delete button is sitting inside aUITableViewCellDeleteConfirmationView
view. This is a private API but using this instead ofUIView
targets only the delete button and not any other button in the cell. So instead of[UIView class]
, use[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]
– Dima
May 13 '15 at 23:50
@Dima Can you confirm if your app passed the review, or they rejected it because you used the private API?
– Septronic
Jan 2 '16 at 11:09
This was a while ago and my app has passed several reviews without a problem.
– Dima
Jan 4 '16 at 22:07
How to add more buttons in this way?
– guhan0
Jul 10 '17 at 12:38
After doing agrep
following this nshipster.com/uiappearance, doesn't seem thatsetAttributedTitle:forState:
is available forUIButton
customization. Can you confirm that this answer still works?
– valcanaia
Mar 18 at 12:01
add a comment |
Well, the only way I've found to set a custom font is to use the appearanceWhenContainedIn
method of the UIAppearance
protocol. This method isn't yet available in Swift, so you have to do it in Objective-C.
I made a class method in a utility Objective-C class to set it up:
+ (void)setUpDeleteRowActionStyleForUserCell
UIFont *font = [UIFont fontWithName:@"AvenirNext-Regular" size:19];
NSDictionary *attributes = @NSFontAttributeName: font,
NSForegroundColorAttributeName: [UIColor whiteColor];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString: @"DELETE"
attributes: attributes];
/*
* We include UIView in the containment hierarchy because there is another button in UserCell that is a direct descendant of UserCell that we don't want this to affect.
*/
[[UIButton appearanceWhenContainedIn:[UIView class], [UserCell class], nil] setAttributedTitle: attributedTitle
forState: UIControlStateNormal];
This works, but it's definitely not ideal. If you don't include UIView in the containment hierarchy, then it ends up affecting the disclosure indicator as well (I didn't even realize the disclosure indicator was a UIButton subclass). Also, if you have a UIButton in your cell that is inside a subview in the cell, then that button will get affected by this solution as well.
Considering the complications, it might be better to just use one of the more customizable open source libraries out there for table cell swipe options.
4
I have figured out an improvement on this answer to avoid affecting other buttons inside the cell. After inspecting the view hierarchy of an expanded cell, I found that the delete button is sitting inside aUITableViewCellDeleteConfirmationView
view. This is a private API but using this instead ofUIView
targets only the delete button and not any other button in the cell. So instead of[UIView class]
, use[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]
– Dima
May 13 '15 at 23:50
@Dima Can you confirm if your app passed the review, or they rejected it because you used the private API?
– Septronic
Jan 2 '16 at 11:09
This was a while ago and my app has passed several reviews without a problem.
– Dima
Jan 4 '16 at 22:07
How to add more buttons in this way?
– guhan0
Jul 10 '17 at 12:38
After doing agrep
following this nshipster.com/uiappearance, doesn't seem thatsetAttributedTitle:forState:
is available forUIButton
customization. Can you confirm that this answer still works?
– valcanaia
Mar 18 at 12:01
add a comment |
Well, the only way I've found to set a custom font is to use the appearanceWhenContainedIn
method of the UIAppearance
protocol. This method isn't yet available in Swift, so you have to do it in Objective-C.
I made a class method in a utility Objective-C class to set it up:
+ (void)setUpDeleteRowActionStyleForUserCell
UIFont *font = [UIFont fontWithName:@"AvenirNext-Regular" size:19];
NSDictionary *attributes = @NSFontAttributeName: font,
NSForegroundColorAttributeName: [UIColor whiteColor];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString: @"DELETE"
attributes: attributes];
/*
* We include UIView in the containment hierarchy because there is another button in UserCell that is a direct descendant of UserCell that we don't want this to affect.
*/
[[UIButton appearanceWhenContainedIn:[UIView class], [UserCell class], nil] setAttributedTitle: attributedTitle
forState: UIControlStateNormal];
This works, but it's definitely not ideal. If you don't include UIView in the containment hierarchy, then it ends up affecting the disclosure indicator as well (I didn't even realize the disclosure indicator was a UIButton subclass). Also, if you have a UIButton in your cell that is inside a subview in the cell, then that button will get affected by this solution as well.
Considering the complications, it might be better to just use one of the more customizable open source libraries out there for table cell swipe options.
Well, the only way I've found to set a custom font is to use the appearanceWhenContainedIn
method of the UIAppearance
protocol. This method isn't yet available in Swift, so you have to do it in Objective-C.
I made a class method in a utility Objective-C class to set it up:
+ (void)setUpDeleteRowActionStyleForUserCell
UIFont *font = [UIFont fontWithName:@"AvenirNext-Regular" size:19];
NSDictionary *attributes = @NSFontAttributeName: font,
NSForegroundColorAttributeName: [UIColor whiteColor];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString: @"DELETE"
attributes: attributes];
/*
* We include UIView in the containment hierarchy because there is another button in UserCell that is a direct descendant of UserCell that we don't want this to affect.
*/
[[UIButton appearanceWhenContainedIn:[UIView class], [UserCell class], nil] setAttributedTitle: attributedTitle
forState: UIControlStateNormal];
This works, but it's definitely not ideal. If you don't include UIView in the containment hierarchy, then it ends up affecting the disclosure indicator as well (I didn't even realize the disclosure indicator was a UIButton subclass). Also, if you have a UIButton in your cell that is inside a subview in the cell, then that button will get affected by this solution as well.
Considering the complications, it might be better to just use one of the more customizable open source libraries out there for table cell swipe options.
edited Jul 28 '16 at 0:53
answered Apr 21 '15 at 16:21
Logan GauthierLogan Gauthier
1735 bronze badges
1735 bronze badges
4
I have figured out an improvement on this answer to avoid affecting other buttons inside the cell. After inspecting the view hierarchy of an expanded cell, I found that the delete button is sitting inside aUITableViewCellDeleteConfirmationView
view. This is a private API but using this instead ofUIView
targets only the delete button and not any other button in the cell. So instead of[UIView class]
, use[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]
– Dima
May 13 '15 at 23:50
@Dima Can you confirm if your app passed the review, or they rejected it because you used the private API?
– Septronic
Jan 2 '16 at 11:09
This was a while ago and my app has passed several reviews without a problem.
– Dima
Jan 4 '16 at 22:07
How to add more buttons in this way?
– guhan0
Jul 10 '17 at 12:38
After doing agrep
following this nshipster.com/uiappearance, doesn't seem thatsetAttributedTitle:forState:
is available forUIButton
customization. Can you confirm that this answer still works?
– valcanaia
Mar 18 at 12:01
add a comment |
4
I have figured out an improvement on this answer to avoid affecting other buttons inside the cell. After inspecting the view hierarchy of an expanded cell, I found that the delete button is sitting inside aUITableViewCellDeleteConfirmationView
view. This is a private API but using this instead ofUIView
targets only the delete button and not any other button in the cell. So instead of[UIView class]
, use[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]
– Dima
May 13 '15 at 23:50
@Dima Can you confirm if your app passed the review, or they rejected it because you used the private API?
– Septronic
Jan 2 '16 at 11:09
This was a while ago and my app has passed several reviews without a problem.
– Dima
Jan 4 '16 at 22:07
How to add more buttons in this way?
– guhan0
Jul 10 '17 at 12:38
After doing agrep
following this nshipster.com/uiappearance, doesn't seem thatsetAttributedTitle:forState:
is available forUIButton
customization. Can you confirm that this answer still works?
– valcanaia
Mar 18 at 12:01
4
4
I have figured out an improvement on this answer to avoid affecting other buttons inside the cell. After inspecting the view hierarchy of an expanded cell, I found that the delete button is sitting inside a
UITableViewCellDeleteConfirmationView
view. This is a private API but using this instead of UIView
targets only the delete button and not any other button in the cell. So instead of [UIView class]
, use [NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]
– Dima
May 13 '15 at 23:50
I have figured out an improvement on this answer to avoid affecting other buttons inside the cell. After inspecting the view hierarchy of an expanded cell, I found that the delete button is sitting inside a
UITableViewCellDeleteConfirmationView
view. This is a private API but using this instead of UIView
targets only the delete button and not any other button in the cell. So instead of [UIView class]
, use [NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]
– Dima
May 13 '15 at 23:50
@Dima Can you confirm if your app passed the review, or they rejected it because you used the private API?
– Septronic
Jan 2 '16 at 11:09
@Dima Can you confirm if your app passed the review, or they rejected it because you used the private API?
– Septronic
Jan 2 '16 at 11:09
This was a while ago and my app has passed several reviews without a problem.
– Dima
Jan 4 '16 at 22:07
This was a while ago and my app has passed several reviews without a problem.
– Dima
Jan 4 '16 at 22:07
How to add more buttons in this way?
– guhan0
Jul 10 '17 at 12:38
How to add more buttons in this way?
– guhan0
Jul 10 '17 at 12:38
After doing a
grep
following this nshipster.com/uiappearance, doesn't seem that setAttributedTitle:forState:
is available for UIButton
customization. Can you confirm that this answer still works?– valcanaia
Mar 18 at 12:01
After doing a
grep
following this nshipster.com/uiappearance, doesn't seem that setAttributedTitle:forState:
is available for UIButton
customization. Can you confirm that this answer still works?– valcanaia
Mar 18 at 12:01
add a comment |
I want to share my solution for ObjC, this is just a trick but works as expected for me.
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
// this just convert view to `UIImage`
UIImage *(^imageWithView)(UIView *) = ^(UIView *view)
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
;
// This is where the magic happen,
// The width and height must be dynamic (it's up to you how to implement it)
// to keep the alignment of the label in place
//
UIColor *(^getColorWithLabelText)(NSString*, UIColor*, UIColor*) = ^(NSString *text, UIColor *textColor, UIColor *bgColor)
UILabel *lbDelete = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 47, 40)];
lbDelete.font = [UIFont boldSystemFontOfSize:11];
lbDelete.text = text;
lbDelete.textAlignment = NSTextAlignmentCenter;
lbDelete.textColor = textColor;
lbDelete.backgroundColor = bgColor;
return [UIColor colorWithPatternImage:imageWithView(lbDelete)];
;
// The `title` which is `@" "` is important it
// gives you the space you needed for the
// custom label `47[estimated width], 40[cell height]` on this example
//
UITableViewRowAction *btDelete;
btDelete = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"Delete");
[tableView setEditing:NO];
];
// Implementation
//
btDelete.backgroundColor = getColorWithLabelText(@"Delete", [UIColor whiteColor], [YJColor colorWithHexString:@"fe0a09"]);
UITableViewRowAction *btMore;
btMore = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleNormal
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"More");
[tableView setEditing:NO];
];
// Implementation
//
btMore.backgroundColor = getColorWithLabelText(@"More", [UIColor darkGrayColor], [YJColor colorWithHexString:@"46aae8"]);
return @[btMore, btDelete];
[YJColor colorWithHexString:<NSString>];
is just to convert hex string to UIColor.
Check the example output screenshot.
add a comment |
I want to share my solution for ObjC, this is just a trick but works as expected for me.
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
// this just convert view to `UIImage`
UIImage *(^imageWithView)(UIView *) = ^(UIView *view)
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
;
// This is where the magic happen,
// The width and height must be dynamic (it's up to you how to implement it)
// to keep the alignment of the label in place
//
UIColor *(^getColorWithLabelText)(NSString*, UIColor*, UIColor*) = ^(NSString *text, UIColor *textColor, UIColor *bgColor)
UILabel *lbDelete = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 47, 40)];
lbDelete.font = [UIFont boldSystemFontOfSize:11];
lbDelete.text = text;
lbDelete.textAlignment = NSTextAlignmentCenter;
lbDelete.textColor = textColor;
lbDelete.backgroundColor = bgColor;
return [UIColor colorWithPatternImage:imageWithView(lbDelete)];
;
// The `title` which is `@" "` is important it
// gives you the space you needed for the
// custom label `47[estimated width], 40[cell height]` on this example
//
UITableViewRowAction *btDelete;
btDelete = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"Delete");
[tableView setEditing:NO];
];
// Implementation
//
btDelete.backgroundColor = getColorWithLabelText(@"Delete", [UIColor whiteColor], [YJColor colorWithHexString:@"fe0a09"]);
UITableViewRowAction *btMore;
btMore = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleNormal
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"More");
[tableView setEditing:NO];
];
// Implementation
//
btMore.backgroundColor = getColorWithLabelText(@"More", [UIColor darkGrayColor], [YJColor colorWithHexString:@"46aae8"]);
return @[btMore, btDelete];
[YJColor colorWithHexString:<NSString>];
is just to convert hex string to UIColor.
Check the example output screenshot.
add a comment |
I want to share my solution for ObjC, this is just a trick but works as expected for me.
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
// this just convert view to `UIImage`
UIImage *(^imageWithView)(UIView *) = ^(UIView *view)
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
;
// This is where the magic happen,
// The width and height must be dynamic (it's up to you how to implement it)
// to keep the alignment of the label in place
//
UIColor *(^getColorWithLabelText)(NSString*, UIColor*, UIColor*) = ^(NSString *text, UIColor *textColor, UIColor *bgColor)
UILabel *lbDelete = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 47, 40)];
lbDelete.font = [UIFont boldSystemFontOfSize:11];
lbDelete.text = text;
lbDelete.textAlignment = NSTextAlignmentCenter;
lbDelete.textColor = textColor;
lbDelete.backgroundColor = bgColor;
return [UIColor colorWithPatternImage:imageWithView(lbDelete)];
;
// The `title` which is `@" "` is important it
// gives you the space you needed for the
// custom label `47[estimated width], 40[cell height]` on this example
//
UITableViewRowAction *btDelete;
btDelete = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"Delete");
[tableView setEditing:NO];
];
// Implementation
//
btDelete.backgroundColor = getColorWithLabelText(@"Delete", [UIColor whiteColor], [YJColor colorWithHexString:@"fe0a09"]);
UITableViewRowAction *btMore;
btMore = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleNormal
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"More");
[tableView setEditing:NO];
];
// Implementation
//
btMore.backgroundColor = getColorWithLabelText(@"More", [UIColor darkGrayColor], [YJColor colorWithHexString:@"46aae8"]);
return @[btMore, btDelete];
[YJColor colorWithHexString:<NSString>];
is just to convert hex string to UIColor.
Check the example output screenshot.
I want to share my solution for ObjC, this is just a trick but works as expected for me.
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
// this just convert view to `UIImage`
UIImage *(^imageWithView)(UIView *) = ^(UIView *view)
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
;
// This is where the magic happen,
// The width and height must be dynamic (it's up to you how to implement it)
// to keep the alignment of the label in place
//
UIColor *(^getColorWithLabelText)(NSString*, UIColor*, UIColor*) = ^(NSString *text, UIColor *textColor, UIColor *bgColor)
UILabel *lbDelete = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 47, 40)];
lbDelete.font = [UIFont boldSystemFontOfSize:11];
lbDelete.text = text;
lbDelete.textAlignment = NSTextAlignmentCenter;
lbDelete.textColor = textColor;
lbDelete.backgroundColor = bgColor;
return [UIColor colorWithPatternImage:imageWithView(lbDelete)];
;
// The `title` which is `@" "` is important it
// gives you the space you needed for the
// custom label `47[estimated width], 40[cell height]` on this example
//
UITableViewRowAction *btDelete;
btDelete = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"Delete");
[tableView setEditing:NO];
];
// Implementation
//
btDelete.backgroundColor = getColorWithLabelText(@"Delete", [UIColor whiteColor], [YJColor colorWithHexString:@"fe0a09"]);
UITableViewRowAction *btMore;
btMore = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleNormal
title:@" "
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath)
NSLog(@"More");
[tableView setEditing:NO];
];
// Implementation
//
btMore.backgroundColor = getColorWithLabelText(@"More", [UIColor darkGrayColor], [YJColor colorWithHexString:@"46aae8"]);
return @[btMore, btDelete];
[YJColor colorWithHexString:<NSString>];
is just to convert hex string to UIColor.
Check the example output screenshot.
edited Feb 20 '17 at 2:08
answered Jan 24 '17 at 6:35
0yeoj0yeoj
3,9322 gold badges16 silver badges37 bronze badges
3,9322 gold badges16 silver badges37 bronze badges
add a comment |
add a comment |
If you use XCode's Debug View Hierarchy to look what is happening in UITableView when the swipe buttons are active, you'll see that UITableViewRowAction items translates to button called _UITableViewCellActionButton
, contained in UITableViewCellDeleteConfirmationView
. One way to change button's properties is to intercept it when it's added to UITableViewCell
. In your UITableViewCell
derived class write something like this:
private let buttonFont = UIFont.boldSystemFontOfSize(13)
private let confirmationClass: AnyClass = NSClassFromString("UITableViewCellDeleteConfirmationView")!
override func addSubview(view: UIView)
super.addSubview(view)
// replace default font in swipe buttons
let s = subviews.flatMap($0).filter $0.isKindOfClass(confirmationClass)
for sub in s
for button in sub.subviews
if let b = button as? UIButton
b.titleLabel?.font = buttonFont
1
Just a note: This uses a private API. It may get rejected, or you may have luck.
– Frederik A. Winkelsdorf
Apr 24 '16 at 16:27
Don't know if this changed for iOS 11 or did in 10... but it looks like that's no longer the class getting added. In Xcode 9 I'm seeing a UISwipeActionStandardButton. As is with attempting to use Private API stuff, the min Apple changes it, your stuff no longer works.
– jhelzer
Jun 24 '17 at 0:35
add a comment |
If you use XCode's Debug View Hierarchy to look what is happening in UITableView when the swipe buttons are active, you'll see that UITableViewRowAction items translates to button called _UITableViewCellActionButton
, contained in UITableViewCellDeleteConfirmationView
. One way to change button's properties is to intercept it when it's added to UITableViewCell
. In your UITableViewCell
derived class write something like this:
private let buttonFont = UIFont.boldSystemFontOfSize(13)
private let confirmationClass: AnyClass = NSClassFromString("UITableViewCellDeleteConfirmationView")!
override func addSubview(view: UIView)
super.addSubview(view)
// replace default font in swipe buttons
let s = subviews.flatMap($0).filter $0.isKindOfClass(confirmationClass)
for sub in s
for button in sub.subviews
if let b = button as? UIButton
b.titleLabel?.font = buttonFont
1
Just a note: This uses a private API. It may get rejected, or you may have luck.
– Frederik A. Winkelsdorf
Apr 24 '16 at 16:27
Don't know if this changed for iOS 11 or did in 10... but it looks like that's no longer the class getting added. In Xcode 9 I'm seeing a UISwipeActionStandardButton. As is with attempting to use Private API stuff, the min Apple changes it, your stuff no longer works.
– jhelzer
Jun 24 '17 at 0:35
add a comment |
If you use XCode's Debug View Hierarchy to look what is happening in UITableView when the swipe buttons are active, you'll see that UITableViewRowAction items translates to button called _UITableViewCellActionButton
, contained in UITableViewCellDeleteConfirmationView
. One way to change button's properties is to intercept it when it's added to UITableViewCell
. In your UITableViewCell
derived class write something like this:
private let buttonFont = UIFont.boldSystemFontOfSize(13)
private let confirmationClass: AnyClass = NSClassFromString("UITableViewCellDeleteConfirmationView")!
override func addSubview(view: UIView)
super.addSubview(view)
// replace default font in swipe buttons
let s = subviews.flatMap($0).filter $0.isKindOfClass(confirmationClass)
for sub in s
for button in sub.subviews
if let b = button as? UIButton
b.titleLabel?.font = buttonFont
If you use XCode's Debug View Hierarchy to look what is happening in UITableView when the swipe buttons are active, you'll see that UITableViewRowAction items translates to button called _UITableViewCellActionButton
, contained in UITableViewCellDeleteConfirmationView
. One way to change button's properties is to intercept it when it's added to UITableViewCell
. In your UITableViewCell
derived class write something like this:
private let buttonFont = UIFont.boldSystemFontOfSize(13)
private let confirmationClass: AnyClass = NSClassFromString("UITableViewCellDeleteConfirmationView")!
override func addSubview(view: UIView)
super.addSubview(view)
// replace default font in swipe buttons
let s = subviews.flatMap($0).filter $0.isKindOfClass(confirmationClass)
for sub in s
for button in sub.subviews
if let b = button as? UIButton
b.titleLabel?.font = buttonFont
answered Apr 21 '16 at 8:40
apetrovicapetrovic
363 bronze badges
363 bronze badges
1
Just a note: This uses a private API. It may get rejected, or you may have luck.
– Frederik A. Winkelsdorf
Apr 24 '16 at 16:27
Don't know if this changed for iOS 11 or did in 10... but it looks like that's no longer the class getting added. In Xcode 9 I'm seeing a UISwipeActionStandardButton. As is with attempting to use Private API stuff, the min Apple changes it, your stuff no longer works.
– jhelzer
Jun 24 '17 at 0:35
add a comment |
1
Just a note: This uses a private API. It may get rejected, or you may have luck.
– Frederik A. Winkelsdorf
Apr 24 '16 at 16:27
Don't know if this changed for iOS 11 or did in 10... but it looks like that's no longer the class getting added. In Xcode 9 I'm seeing a UISwipeActionStandardButton. As is with attempting to use Private API stuff, the min Apple changes it, your stuff no longer works.
– jhelzer
Jun 24 '17 at 0:35
1
1
Just a note: This uses a private API. It may get rejected, or you may have luck.
– Frederik A. Winkelsdorf
Apr 24 '16 at 16:27
Just a note: This uses a private API. It may get rejected, or you may have luck.
– Frederik A. Winkelsdorf
Apr 24 '16 at 16:27
Don't know if this changed for iOS 11 or did in 10... but it looks like that's no longer the class getting added. In Xcode 9 I'm seeing a UISwipeActionStandardButton. As is with attempting to use Private API stuff, the min Apple changes it, your stuff no longer works.
– jhelzer
Jun 24 '17 at 0:35
Don't know if this changed for iOS 11 or did in 10... but it looks like that's no longer the class getting added. In Xcode 9 I'm seeing a UISwipeActionStandardButton. As is with attempting to use Private API stuff, the min Apple changes it, your stuff no longer works.
– jhelzer
Jun 24 '17 at 0:35
add a comment |
This seems to work, at least for setting the font color:
- (void)setupRowActionStyleForTableViewSwipes
UIButton *appearanceButton = [UIButton appearanceWhenContainedInInstancesOfClasses:@[[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]]];
[appearanceButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
add a comment |
This seems to work, at least for setting the font color:
- (void)setupRowActionStyleForTableViewSwipes
UIButton *appearanceButton = [UIButton appearanceWhenContainedInInstancesOfClasses:@[[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]]];
[appearanceButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
add a comment |
This seems to work, at least for setting the font color:
- (void)setupRowActionStyleForTableViewSwipes
UIButton *appearanceButton = [UIButton appearanceWhenContainedInInstancesOfClasses:@[[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]]];
[appearanceButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
This seems to work, at least for setting the font color:
- (void)setupRowActionStyleForTableViewSwipes
UIButton *appearanceButton = [UIButton appearanceWhenContainedInInstancesOfClasses:@[[NSClassFromString(@"UITableViewCellDeleteConfirmationView") class]]];
[appearanceButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
answered Mar 22 '16 at 23:08
AlexandruAlexandru
6,21810 gold badges76 silver badges149 bronze badges
6,21810 gold badges76 silver badges149 bronze badges
add a comment |
add a comment |
You could use UIButton.appearance
to style the button inside the row action. Like so:
let buttonStyle = UIButton.appearance(whenContainedInInstancesOf: [YourViewController.self])
let font = UIFont(name: "Custom-Font-Name", size: 16.0)!
let string = NSAttributedString(string: "BUTTON TITLE", attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.foregroundColor : UIColor.green])
buttonStyle.setAttributedTitle(string, for: .normal)
Note: this will affect all of your buttons in this view controller.
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.
– Dwhitz
Mar 27 at 14:17
add a comment |
You could use UIButton.appearance
to style the button inside the row action. Like so:
let buttonStyle = UIButton.appearance(whenContainedInInstancesOf: [YourViewController.self])
let font = UIFont(name: "Custom-Font-Name", size: 16.0)!
let string = NSAttributedString(string: "BUTTON TITLE", attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.foregroundColor : UIColor.green])
buttonStyle.setAttributedTitle(string, for: .normal)
Note: this will affect all of your buttons in this view controller.
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.
– Dwhitz
Mar 27 at 14:17
add a comment |
You could use UIButton.appearance
to style the button inside the row action. Like so:
let buttonStyle = UIButton.appearance(whenContainedInInstancesOf: [YourViewController.self])
let font = UIFont(name: "Custom-Font-Name", size: 16.0)!
let string = NSAttributedString(string: "BUTTON TITLE", attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.foregroundColor : UIColor.green])
buttonStyle.setAttributedTitle(string, for: .normal)
Note: this will affect all of your buttons in this view controller.
You could use UIButton.appearance
to style the button inside the row action. Like so:
let buttonStyle = UIButton.appearance(whenContainedInInstancesOf: [YourViewController.self])
let font = UIFont(name: "Custom-Font-Name", size: 16.0)!
let string = NSAttributedString(string: "BUTTON TITLE", attributes: [NSAttributedString.Key.font : font, NSAttributedString.Key.foregroundColor : UIColor.green])
buttonStyle.setAttributedTitle(string, for: .normal)
Note: this will affect all of your buttons in this view controller.
edited Mar 27 at 14:31
answered Mar 27 at 13:53
FaipdeoiadFaipdeoiad
761 silver badge3 bronze badges
761 silver badge3 bronze badges
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.
– Dwhitz
Mar 27 at 14:17
add a comment |
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.
– Dwhitz
Mar 27 at 14:17
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.
– Dwhitz
Mar 27 at 14:17
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.
– Dwhitz
Mar 27 at 14:17
add a comment |
Here is some Swift Code that might be helpful:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) ->[AnyObject]?
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
UIButton.appearance().setAttributedTitle(NSAttributedString(string: "Your Button", attributes: attributes), forState: .Normal)
// Things you do...
This will manipulate all buttons in your application.
4
Actually this will manipulate ALL buttons throughout your application. It appears that after this code is executed all buttons in the application are affected by this code. Not an ideal solution unless you don't have any other buttons in your application, which is probably not the case.
– northdig
Aug 12 '15 at 22:20
i edited my last line to correct my post
– alexdd55
Aug 13 '15 at 9:05
add a comment |
Here is some Swift Code that might be helpful:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) ->[AnyObject]?
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
UIButton.appearance().setAttributedTitle(NSAttributedString(string: "Your Button", attributes: attributes), forState: .Normal)
// Things you do...
This will manipulate all buttons in your application.
4
Actually this will manipulate ALL buttons throughout your application. It appears that after this code is executed all buttons in the application are affected by this code. Not an ideal solution unless you don't have any other buttons in your application, which is probably not the case.
– northdig
Aug 12 '15 at 22:20
i edited my last line to correct my post
– alexdd55
Aug 13 '15 at 9:05
add a comment |
Here is some Swift Code that might be helpful:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) ->[AnyObject]?
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
UIButton.appearance().setAttributedTitle(NSAttributedString(string: "Your Button", attributes: attributes), forState: .Normal)
// Things you do...
This will manipulate all buttons in your application.
Here is some Swift Code that might be helpful:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) ->[AnyObject]?
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
UIButton.appearance().setAttributedTitle(NSAttributedString(string: "Your Button", attributes: attributes), forState: .Normal)
// Things you do...
This will manipulate all buttons in your application.
edited Aug 13 '15 at 9:04
answered Jul 31 '15 at 9:02
alexdd55alexdd55
1,02714 silver badges18 bronze badges
1,02714 silver badges18 bronze badges
4
Actually this will manipulate ALL buttons throughout your application. It appears that after this code is executed all buttons in the application are affected by this code. Not an ideal solution unless you don't have any other buttons in your application, which is probably not the case.
– northdig
Aug 12 '15 at 22:20
i edited my last line to correct my post
– alexdd55
Aug 13 '15 at 9:05
add a comment |
4
Actually this will manipulate ALL buttons throughout your application. It appears that after this code is executed all buttons in the application are affected by this code. Not an ideal solution unless you don't have any other buttons in your application, which is probably not the case.
– northdig
Aug 12 '15 at 22:20
i edited my last line to correct my post
– alexdd55
Aug 13 '15 at 9:05
4
4
Actually this will manipulate ALL buttons throughout your application. It appears that after this code is executed all buttons in the application are affected by this code. Not an ideal solution unless you don't have any other buttons in your application, which is probably not the case.
– northdig
Aug 12 '15 at 22:20
Actually this will manipulate ALL buttons throughout your application. It appears that after this code is executed all buttons in the application are affected by this code. Not an ideal solution unless you don't have any other buttons in your application, which is probably not the case.
– northdig
Aug 12 '15 at 22:20
i edited my last line to correct my post
– alexdd55
Aug 13 '15 at 9:05
i edited my last line to correct my post
– alexdd55
Aug 13 '15 at 9:05
add a comment |
I think you can use this method to change the appearance only in one (or more, you can define it) viewcontrollers:
//create your attributes however you want to
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
//Add more view controller types in the []
UIButton.appearanceWhenContainedInInstancesOfClasses([ViewController.self])
Hope this helped.
add a comment |
I think you can use this method to change the appearance only in one (or more, you can define it) viewcontrollers:
//create your attributes however you want to
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
//Add more view controller types in the []
UIButton.appearanceWhenContainedInInstancesOfClasses([ViewController.self])
Hope this helped.
add a comment |
I think you can use this method to change the appearance only in one (or more, you can define it) viewcontrollers:
//create your attributes however you want to
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
//Add more view controller types in the []
UIButton.appearanceWhenContainedInInstancesOfClasses([ViewController.self])
Hope this helped.
I think you can use this method to change the appearance only in one (or more, you can define it) viewcontrollers:
//create your attributes however you want to
let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] as Dictionary!
//Add more view controller types in the []
UIButton.appearanceWhenContainedInInstancesOfClasses([ViewController.self])
Hope this helped.
answered Jan 2 '16 at 11:38
SeptronicSeptronic
81211 silver badges24 bronze badges
81211 silver badges24 bronze badges
add a comment |
add a comment |
//The following code is in Swift3.1
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
let rejectAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2715nReject") action, indexPath in
print("didtapReject")
rejectAction.backgroundColor = UIColor.gray
let approveAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2713nApprove") action, indexPath in
print("didtapApprove")
approveAction.backgroundColor = UIColor.orange
return [rejectAction, approveAction]
This doesn't seem to change the font color at all.
– Travis M.
Aug 23 '17 at 18:38
add a comment |
//The following code is in Swift3.1
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
let rejectAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2715nReject") action, indexPath in
print("didtapReject")
rejectAction.backgroundColor = UIColor.gray
let approveAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2713nApprove") action, indexPath in
print("didtapApprove")
approveAction.backgroundColor = UIColor.orange
return [rejectAction, approveAction]
This doesn't seem to change the font color at all.
– Travis M.
Aug 23 '17 at 18:38
add a comment |
//The following code is in Swift3.1
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
let rejectAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2715nReject") action, indexPath in
print("didtapReject")
rejectAction.backgroundColor = UIColor.gray
let approveAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2713nApprove") action, indexPath in
print("didtapApprove")
approveAction.backgroundColor = UIColor.orange
return [rejectAction, approveAction]
//The following code is in Swift3.1
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
let rejectAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2715nReject") action, indexPath in
print("didtapReject")
rejectAction.backgroundColor = UIColor.gray
let approveAction = TableViewRowAction(style: UITableViewRowActionStyle.default, title: "u2713nApprove") action, indexPath in
print("didtapApprove")
approveAction.backgroundColor = UIColor.orange
return [rejectAction, approveAction]
answered May 11 '17 at 5:32
NrvNrv
1335 bronze badges
1335 bronze badges
This doesn't seem to change the font color at all.
– Travis M.
Aug 23 '17 at 18:38
add a comment |
This doesn't seem to change the font color at all.
– Travis M.
Aug 23 '17 at 18:38
This doesn't seem to change the font color at all.
– Travis M.
Aug 23 '17 at 18:38
This doesn't seem to change the font color at all.
– Travis M.
Aug 23 '17 at 18:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29049318%2fhow-to-do-custom-font-and-color-in-uitableviewrowaction-without-storyboard%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Check my answer on this post: stackoverflow.com/a/36145706/2734651
– Lee Andrew
Mar 22 '16 at 3:41