how to customize scroll color of tableview in iphone sdk? - iphone

I want to set scroll style to pink color in tableview.please give any suggestion for that.

but only available from this colors
[tableview setIndicatorStyle:UIScrollViewIndicatorStyleWhite];
Replace UIScrollViewIndicatorStyleWhite to anything from this typedef.
typedef enum {
UIScrollViewIndicatorStyleDefault,
UIScrollViewIndicatorStyleBlack,
UIScrollViewIndicatorStyleWhite
} UIScrollViewIndicatorStyle;

For the moment is not possible set a custom color in the Scroll. the only posible colors are white and black.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/doc/uid/TP40006922-CH3-SW5

This code works for me, Swift-3
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let verticalIndicator = scrollView.subviews.last as? UIImageView
verticalIndicator?.image = nil
verticalIndicator?.backgroundColor = UIColor.red
}

Related

Swift how to remove uisegmentControl default black backgroundColor?

I know a lot of people asked this question, but nothing helps. My controller1 presents a new controller2 from storyboard. Controler1's background color is black. My customized segmentcontrol background color and selectedTintColor work well, but always show a black background color first. I tried every way, but not working. In storyboard and code, all no this black color. Thanks!
override func viewDidLoad() {
let bgColor = uIColor. // my customized color)
segmentControl.backgroundColor = bgColor
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
connectionSegmentControl.selectedSegmentIndex = 0
toggleSegmentTintColor()
}
private func toggleSegmentTintColor() {
// I set my customized selected tint color here, it works.
}
If you do this in viewDidAppear, its too late: the view is on the screen. The hack way to do it is in viewDidlaod or viewWillAppear. The right way to do it is to to use UIAppearance proxy on app launch to set the tint color for your object globally:
UISegmentedControl.appearance().tintColor = UIColor.clear
You can also set the tint color for the whole app by setting it on the root window, but then it affects more than just the segmented controls.

How to change color of navigationBar & BarButtonItem with scroll

I want to change the background color of UINavigationBar and the UIBarButtonItem inside this NavigationBar smothly while I scroll down the TableView. I saw this in the AirBNB app and have no idea how to do somthing like this. Thanks for any help
Conform to UIScrollViewDelegate and make sure that your tableView/CollectionView delegate is set to the current ViewController.
Implement scrollViewDidScroll(:) method.
Decide your preferred offset to change NavigationBarColor.
If you offset condition is met then change your NavigationBarColor.
SUMMARY
Class UIViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offset = scrollView.contentOffset.y
if offset > 1 { // Or choose any desired offset
// TODO:- Change your color for offset greater than 1
}else {
// TODO: - Change your nav bar for offset less than 1
}
}
}

Detect if label touches navigation bar

I am trying to make view that is scrollable. That viewcontroller contains also navbar. Now my goal is to resize my view if the title in that view touches the navbar. How should I do it?
This is how my view looks like(note that the navBar is just transparent):
What I want after the title collision:
I know that I can achieve it in scrollViewDidScroll delegate function, but how?
Well you can track label position using convertRect: method as
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let labelTop = label.rectCorrespondingToWindow.minY
let navBottom = self.navigationController?.navigationBar.rectCorrespondingToWindow.maxY
if navBottom == labelTop {
// do what you want to do
}
}
extension UIView{
var rectCorrespondingToWindow:CGRect{
return self.convert(self.bounds, to: nil)
}
}

NSSearchField: How to hide icon and border?

This is kind of a duplicate of this question. Because everything I know about Swift is Swift3, I`m wondering if someone could "translate" the suggested solution in this answer.
Also:
I made a NSSearchfield without border, put it in a framed view, and it still shows the gray border. I would be curious of how to disable the animated gray border and maybe even how to change the color of the gray "search" line.
My ugly result now looks like this:
It would be a big help if someone could tell me how to manage this difficult NSSearchfield.
//UPDATE
According to firstinq´s answer, the icon now disappeared, which is great. But still, there is this disturbing animated gray border. Which I can´t understand: The NSSearchFielt is inside a NSView (blue border). So everything outside the NSView should be hidden, right?. So why am I still seeing the gray border? cell.isBordered = falsehas no effect.
Any advice how to handle that?
This is how I draw the border of the NSView:
class SearchFieldBorder: NSView {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
self.layer?.borderWidth = 1
self.layer?.borderColor = NSColor.blue.cgColor
}
}
To hide the icon: cast the cell to NSSearchFieldCell and set the cell's searchButtonCell to transparent. Possible swift3 version:
if let cell = self.searchField.cell as? NSSearchFieldCell {
cell.searchButtonCell?.isTransparent = true
}
Here searchField is an NSSearchField
To remove the focus border:
searchField.focusRingType = .none
To change grey line/cursor it would be better to subclass the NSSearchField and override the methods.
You can get an idea from here.
I'll supplement the answer above.
To hide the search icon, assign a nil to the SearchButtonCell property
if let cell = searchField.cell as? NSSearchFieldCell {
cell.searchButtonCell = nil
}

Remove thin-like border when focusing a custom UITableCell

Question:
How do I remove the thin-like white border when focusing a custom UITableCell?
(In all honesty it has nothing to do with the border of a cell, I've tried modifying the color of the border to see)
Description:
This seems to only occur when I leave the default focus style for the table cell via the storyboard, when I remove the default focus animation on the cell, the white borders do not appear (but then I have to implement my own custom animation..)
I've attempted to play around with different colors and tints but that didn't seem to work.
Above gif is showing the white border appearing when focusing a specific UITableCell
Screen shots of my UITableViewController Storyboard.
Image above is a screenshot of the attribute inspector for the UITableViewCell
Image above is a screenshot of the attribute inspector for the Content View of my UITableViewCell
Image above is a screenshot of the attribute inspector for the UITableView
Updated:
It's not border, but shadow. Now UITableViewCellFocusStyle.default is probably setting shadow to cell while focusing and when you scroll then even after hiding it, shadow is visible for a short period.
You can hide the shadow like this:
func tableView(_ tableView: UITableView, didUpdateFocusIn context: UITableViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
if let cell = context.nextFocusedView as? CustomTableViewCell {
cell.layer.shadowOpacity = 0
cell.layer.masksToBounds = true
}
//other configurations
}
Note 1: Shadow appears for a short period of time using above code. Use below code for no shadow.
Alternatively, you can use UITableViewCellFocusStyle.custom and give default focus animation without shadow manually like this:
func tableView(_ tableView: UITableView, didUpdateFocusIn context: UITableViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
let xScale = 1.008
let yScale = 1.008
if let cell = context.nextFocusedView as? CustomTableViewCell {
coordinator.addCoordinatedAnimations({ () -> Void in
cell.transform = CGAffineTransform(scaleX: CGFloat(xScale), y: CGFloat(yScale))
}, completion: nil)
}
if let previous = context.previouslyFocusedView as? CustomTableViewCell {
coordinator.addCoordinatedAnimations({ () -> Void in
previous.transform = CGAffineTransform.identity
}, completion: nil)
}
}
Note:
Try playing with xScale & yScale values for better animation.
Change your cell Focus style into Custom