How to disable the cross and other touch events in ios-charts? - ios

i have a Line Chart view in my iOS app.
#IBOutlet weak var lineChartView: LineChartView!
the zooming and touching is enabled. I do not let the user do anything in the chart, even selecting is not allowed.
I tried:
self.lineChartView.pinchZoomEnabled = false
self.lineChartView.dragEnabled = false
self.lineChartView.dragDecelerationEnabled = false
but without any luck. I can still touch the graph and see the cross. I even can pinch to zoom the graph.
How can i turn this behaviour off?+

Doh!
in storyboard I can disable "User Interaction Enabled".
that do the trick.

The accepted solution didn't work for my barChartView for some reason.
Instead, setting barChartView.isUserInteractionEnabled = false did the trick.
So, for the OP, the following should work self.lineChartView.isUserInteractionEnabled = false

In case anyone would like it to still drag but only disable zooming, you can try
self.lineChart.setScaleEnabled(false)

I just used
dataSet.highlightColor = .clear

If you want to still have the interactive chart Try these:
chartView.dragXEnabled = false
chartView.dragYEnabled = false
chartView.scaleXEnabled = false
chartView.scaleYEnabled = false

Related

How to add a straight line into UISearchBar next to right Search icon?

I already had a UISearchBar (search icon is bookmarkButton inside searchTextField) like that:
Search Bar
searchBar code
private func setupSearchBar() {
searchBar.translatesAutoresizingMaskIntoConstraints = false
searchBar.backgroundImage = UIImage()
searchBar.setImage(UIImage(), for: .search, state: .normal)
searchBar.showsBookmarkButton = true
searchBar.setImage(UIImage(systemName: "magnifyingglass")?.withTintColor(self.darklightcolor, renderingMode: .alwaysOriginal).applyingSymbolConfiguration(.init(pointSize: 22)), for: .bookmark, state: .normal)
cancelButtonSearchBar = UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self])
cancelButtonSearchBar.tintColor = .systemPink
searchBar.layer.borderColor = darklightcolor.cgColor
searchBar.layer.borderWidth = 1.5
searchBar.layer.cornerRadius = 19
searchBar.layer.backgroundColor = UIColor.clear.cgColor
searchBar.searchTextField.backgroundColor = .clear
searchBar.delegate = self
view.addSubview(searchBar)
}
Now I want to add a gray line to searchBar next to search icon like this
But I cant find anyway to add that line. Can anyone help me?
That separator is not part of UISearchbar. You should not play with the internal view hierarchy of the searchbar since it may change and it is going to break your implementation. There is also something in your code that raises a flag, setting the appearance() for buttons when contained in UISearchbars may lead to unintended tinting of buttons in other searchbars within the app. As a practice if you want to set it for all, I would suggest applying those appearance modifications in a single place, otherwise you will end up looking everywhere in your code for the one place where you set the value.
The best approach if that design is so important would be to implement something custom, at that point, it would be up to you to make the hierarchy and you could modify the hierarchy because it was created by you.
That being said, if you still want to continue with this approach, you may add this extension:
extension UISearchBar {
var cancelButtonView: UIView? {
self.searchTextField
.superview?
.subviews
.first(where: { $0.description.contains("Button") })
}
}
And use it when setting constraints for the view you've added.

iOS Charts Disable Zoom

How do you disable zoom for iOS Charts but not completely stop user interaction? For example, still using the highlight tap. This takes care of the zoom, but it disables everything else as well.
chartView.userInteractionEnabled = false
To disable zoom, but not impact other chart interaction, make these adjustments:
chartView.doubleTapToZoomEnabled = false
chartView.pinchZoomEnabled = false
chartView.scaleXEnabled = false
chartView.scaleYEnabled = false

Horizontal Bar chart Swift

I want it like this:
But what I can do is, how to get rid of little red label:
Core code for the chart:
var barchart = [BarChartDataEntry]()
// some values
barchart.append(value1)
barchart.append(value2)
barchart.append(value3)
let barData = BarChartDataSet(values: barchart, label: "")
barData.colors = [NSUIColor.red]
let data = BarChartData(dataSet: barData)
data.barWidth = 0.35
cell.barChart.data = data
cell.barChart.scaleYEnabled = false
cell.barChart.chartDescription?.text = ""
cell.barChart.scaleXEnabled = false
cell.barChart.pinchZoomEnabled = false
cell.barChart.doubleTapToZoomEnabled = false
cell.barChart.rightAxis.enabled = false
cell.barChart.xAxis.drawGridLinesEnabled = false
cell.barChart.leftAxis.drawGridLinesEnabled = false
cell.barChart.leftAxis.drawAxisLineEnabled = false
cell.barChart.xAxis.drawAxisLineEnabled = false
cell.barChart.xAxis.drawLabelsEnabled = false
cell.barChart.leftAxis.drawLabelsEnabled = false
cell.barChart.animate(yAxisDuration: 1.5, easingOption: .easeInOutQuart)
return cell
I would like to set max value and make labels rounded as in the image above. I am using https://github.com/danielgindi/Charts.
You can implement the similar UI by using the UIProgressView
First, you can set the Label on top, then a UIProgressView and repeat the same. For other two progresses.
You can add the proper constraints and achieve it.
Refer this Sample Demo for achieving the same.
Hope it helps.
Just add this line where you are setting chartView
cell.barChart.legend.enabled = false
It works for me.
Use UIProgressView component in storyboard and create the outlet
#IBOutlet var progressViewWalk: UIProgressView!
You can set the required progress by:-
progressViewWalk.progress = Float(YOURValue)/100
Set your required Track tint color Progress tint color in Attribute Inspector.

How to disable gestures (lock - no move/pan/zoom) on mapView - here maps ios sdk/swift 3?

How to Disable mapView gestures on iOS?
On Android:
mapFragment.getMapGesture().setAllGesturesEnabled(false);
Just disable user interaction...
mapView.isUserInteractionEnabled = false
For anyone looking to disable movement of the gms map while still being able to add custom gesture recognizers, you can use the following code for Swift 4.1
gmsMapView.settings.tiltGestures = false
gmsMapView.settings.rotateGestures = false
gmsMapView.settings.zoomGestures = false
gmsMapView.settings.scrollGestures = false`
The key is to disable zooms and scrolls, such as:
mapView.isUserInteractionEnabled = false
This is Enough.
In the latest SDK, you can switch off gestures:
mapView.settings.setAllGesturesEnabled(false)

How to lock the scroll view in place?

I want to lock the scrollView when my segmented Control comes to top of the screen. How can I do this in swift? What's the code of this? How to compute the distance between the top of the segmented control and top of the view controller? It means how can I find the true place for locking scrollView?
After Swift 4.0 it has changed to
scrollView.isScrollEnabled = false
and
scrollView?.isScrollEnabled = true
Just flip the scrollEnabled boolean:
yourScrollView.scrollEnabled = false
To make it scroll again:
yourScrollView.scrollEnabled = true

Resources