Hide grey color when cell is touched - objective-c

I'm making an app with a multiple cell selection (I use checkmark) like this
The problem is that when I click on a cell, it remains gray and is really bad. How can I fix it?

If you do not want to show grey selection at all:
Select the UITableViewCell in Storyboard
In Inspector, set selected to none
You can find more options to set it programatically in this answer.

try this code at didSelectRowAt#
cell.selectionStyle = UITableViewCellSelectionStyleNone

You can use this:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
or
cell.selectionStyle = UITableViewCellSelectionStyle.None

Related

UITableViewAutomaticDimension with imageview

I have a tableview that contains a custom cell. The custom cell has an imageview and a label. I want to resize the cell based on the text in the label because the imageview dimensions are constant. The imageview takes up the majority of the cell being centered and the label is below it.
self->tableView.rowHeight = UITableViewAutomaticDimension;
I am using this line of code to do so, and I have also set up constraints on the storyboard. When the code runs the image does not show, only the label and the cell is not even resized based off of the text. When I set the view to a default height, both are shown. I am unsure why this is not working. My only thought is that my constraints are incorrect. I have successfully used this with 2 labels but not an imageview. Any help would be appreciated. I would show a picture regarding my constraints, but I can not due to my status.
If you have layout like this of your tableViewCell then set your constraints as shown in below.
You also need to set estimatedRowHeight of your tableView.
self.tableView.estimatedRowHeight = 200;
self.tableView.rowHeight = UITableViewAutomaticDimension;
Remove height constraint form label if set and set label noOflines = 0. It will help you.
Make you set the following
-label numberOfLines to 0
-don't set height for label
-in the bottom contraint between the label and the cell contentView, set it to greater than or equal to e.g 5
Then call the methods below
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}

Separator Color of one cell

how can i change the color of the separator line of my table view? But i want change only the first line.
This works for the whole tableview.
tableView.separatorColor = [UIColor blueColor];
Subclass UITableViewCell and put a line UIView at the top of the cell that can be accessed via a property (in storyboard or in code, whatever you like)
In cellForRowAtIndexPath set the color of the line view according to the row.
If you only want to change the first line, and by that you mean the top one as opposed to the line in between the first and second rows, then consider using UITableView's tableHeaderView.
try this
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 0 {
tableView.separatorColor = UIColor.blueColor()
} else {
tableView.separatorColor = UIColor.greenColor()
}
}

iOS8 (Custom Keyboard) how make background transparent?

I'm working on custom keyboard for iOS 8. By default it has grey background color.
If you are setting some color for its view background - all is OK, but how can I make it transparent? (UIColor.clearColor() doesn't work)
Are you using a xib file to load the view ?
Or did you do everything programmatically ?
I did mine using a xib file, I set the background color in the story to the default empty one.
Then before viewDidLoad I set it up to clearcolor, qnd it works. I got the same background than the default keyboard.
I haven't tried it with a keyboard, but can you set a background PNG? If so, create a 1px by 1px PNG that's clear (keep the transparency in your PNG). Use that as your background image. It appears there is currently a bug in the SDK that is causing this problem.
Unfortunately you can't display the keyboard's background as .clear (transparent) but you can change it to other colors. More on that:
Remember when using a nib, there are 2 views - the nib's view and the ViewController's view. You can change the nib's background to .clear, but that just show's the ViewController's view (in this case, KeyboardViewController)
override func viewDidLoad() {
super.viewDidLoad()
let keyboardNib = UINib(nibName: "KeyboardView", bundle: nil)
let keyboardView = keyboardNib.instantiate(withOwner: self, options: nil) [0] as? UIView
view.backgroundColor = .red
keyboardView.backgroundColor = .clear
}
Where the above really comes in handy is when you want the nib's view to match the ViewController's view (keyboardView.backgroundColor = view.backgroundColor also does the same).
If you're just wanting to change the nib's color, you can just set the nib's background color to whatever color you want since its in front of the keyboardViewController's view.
override func viewDidLoad() {
super.viewDidLoad()
let keyboardNib = UINib(nibName: "KeyboardView", bundle: nil)
let keyboardView = keyboardNib.instantiate(withOwner: self, options: nil) [0] as? UIView
keyboardView.backgroundColor = .red
}

Cursor invisible in UISearchBar iOS 7

I have UISearchBar in UITableView as a table header. When I push the UISearchBar for start searching, this method is being triggered
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
for UISearchDisplayController.
But result is like that;
As you can see, there is no cursor, I can start typing and search, everything works fine. Also it's invisible only in iOS 7. However, with iOS 6.1 and iOS 7.1 Beta 3 I could see the cursor. So how can I make UISearchBar cursor visible or how can I add cursor in my UISearchBar?
Cursor in the search bar takes color from Search Bar -> View -> Tint Color property.
In your case, it is set to White color, so it becomes invisible.
try using with
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
self.navigationItem.titleView.tintColor = [UIColor blueColor];
}
hope this will help you
Try setting text field tint color using UIAppearance
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor: [UIColor darkGrayColor]];
If you want the cursor and cancel button to be different colors...
Start by setting the view's tint color (not the bar tint) in the storyboard editor, which will be applied to both the cursor and cancel button.
To make the cursor a different color, you need to do it programatically. The text field is nested a couple levels down in the searchBar's subviews. Use this setTextFieldTintColor helper function to traverse all of the subviews.
#IBOutlet weak var searchBar: UISearchBar!
override func viewDidLoad() {
super.viewDidLoad()
// set tint color for all subviews in searchBar that are of type UITextField
setTextFieldTintColor(to: UIColor.darkText, for: searchBar)
}
func setTextFieldTintColor(to color: UIColor, for view: UIView) {
if view is UITextField {
view.tintColor = color
}
for subview in view.subviews {
setTextFieldTintColor(to: color, for: subview)
}
}
The end result looks like this:
Try this it's only one line of code to solve your problem , Change cursor tintColor property white to blue.
searchBar.tintColor = [UIColor blueColor];
Hope this will help to someone .
Your cursor is white because your tintColor property on UISearchBar is set to white.
If you want Cancel btn to be white, but cursor to be black you can use:
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = .black

How to make specific UITableViewCell to be visible on screen while having more rows in UITableView

I am having 20 rows in a table view, and I have designed (or say resized) UITableView in half of the screen (Using IB) and in half screen I am showing the stuff related to particular UITableViewCell. Which cell's details are going to be shown in the half screen is decided runtime. I want the cell being visible while loading the view for say second last cell.
How can I achieve this?
I found the easiest way to ensure that a whole cell is visible is to ask the tableview to make sure that the rect for the cell is visible:
[tableView scrollRectToVisible:[tableView rectForRowAtIndexPath:indexPath] animated:YES];
An easy way to test it is just to put that into -(void)tableView:didSelectRowAtIndexPath: - tapping any cell will then scroll it into place if it's partially hidden.
UITableView class offers :
-(void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath
atScrollPosition:(UITableViewScrollPosition)scrollPosition
animated:(BOOL)animated;
which seems to be what you are looking for.
The NSIndexPath object can be built using :
+(NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
Try scrollToRowAtIndexPath:atScrollPosition:animated::
NSUInteger indexArray[] = {1,15};
NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:indexArr length:2];
[yourTableView scrollToRowAtIndexPath:indexPath atScrollPosition: UITableViewScrollPositionTop animated:YES];
Swift 4 version of Nico teWinkel's answer, which worked best for me:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.scrollToRow(at: indexPath, at: .middle, animated: true) //scrolls cell to middle of screen
}
Swift 5 version of Nico teWinkel's answer making use of UITableview's scroll rect to visible method.
let indexPath = IndexPath(row: 0, section: 0)
let cellRect = myTableView.rectForRow(at: indexPath)
myTableView.scrollRectToVisible(cellRect, animated: true)
Use like this,
let indexPath = IndexPath(row:row, section:section)
self.tableView.scrollToRow(at:indexPath, at:.top, animated:true)