ios Charts change grid lines color - ios

I have made a small application measuring Heart Rate from iWatch. The chart is working as intended showing current heart rate, but I have several issues with the design. Below you can find the image of my chart and its setting in swift.
ios Chart
//chart set up
self.chtChart.delegate = self as? ChartViewDelegate
self.chtChart.noDataTextColor = UIColor.white
self.chtChart.noDataText = "Press Start button to display the chart"
let set_a: LineChartDataSet = LineChartDataSet(entries:[ChartDataEntry(x: Double(Int(0)), y: self.valueHR)], label: "BPM")
set_a.drawCirclesEnabled = false
set_a.setColor(UIColor.systemPink)
set_a.drawValuesEnabled = false
set_a.lineWidth = 5.0
//remove vertical grid and labels
self.chtChart.xAxis.drawGridLinesEnabled = false
self.chtChart.rightAxis.drawLabelsEnabled = false
self.chtChart.xAxis.drawLabelsEnabled = false
//change label 'BPM' color
self.chtChart.legend.textColor = UIColor.white
//change left numbers (bpm values)
self.chtChart.leftAxis.labelTextColor = UIColor.white
//change right border line color
self.chtChart.rightAxis.axisLineColor = UIColor.white
//change left border line to white
self.chtChart.leftAxis.axisLineColor = UIColor.white
//change values from decimal to int on left axis
let fmt = NumberFormatter()
fmt.numberStyle = .decimal
fmt.maximumFractionDigits = 0
fmt.groupingSeparator = ","
fmt.decimalSeparator = "."
self.chtChart.leftAxis.valueFormatter = DefaultAxisValueFormatter.init(formatter: fmt)
self.chtChart.data = LineChartData(dataSets: [set_a])
As you can see, my chart does not have the bottom border and I also can't change the color of the grid line inside the chart (I want to change it to white). I have tried following commands but nothing was changed:
self.chtChart.xAxis.axisLineColor = UIColor.white
self.chtChart.borderColor = UIColor.white
self.chtChart.xAxis.gridColor = UIColor.white

I was going through all possible attributes and found that adding the lines:
self.chtChart.xAxis.axisLineColor = UIColor.white
self.chtChart.rightAxis.gridColor = UIColor.white
solves the problem with the bottom border and also changes the color of the grid lines to white.
Edit: the bottom line problem still appears to be an issue. It does not show on the screen.
Edit2: adding the all borders at once and setting their color seems to solve the issue:
self.chtChart.drawBordersEnabled = true
self.chtChart.borderColor = UIColor.white

Related

FSCalendarScopeWeek issue- swift

I'm using fscalender on my project which I have to use both month scope and week scope on different view controller.so when I'm using week scope date title size is getting smaller, but when I increase the view height its getting perfect.but my view should have an fixed size so how can I fix this problem.
this is my calendar now
here I converted the round background to rectangle by
calendarObj.appearance.borderRadius = 0
The above week title is implemented with stackview.
This is actually I want
the rectangle border is not showing full.How to resolve this?Im new to this iOS
I Tried This On A view, I have Added only Few Lines, an it is working as you want.
calendarView.dataSource = self
calendarView.delegate = self
calendarView.scrollDirection = .vertical
calendarView.scope = .week
calendarView.backgroundColor = .clear
calendarView.allowsMultipleSelection = false
calendarView.appearance.selectionColor = .none
calendarView.appearance.borderSelectionColor = .red
calendarView.appearance.todayColor = .clear
calendarView.appearance.titleTodayColor = .black
calendarView.appearance.weekdayTextColor = .black
calendarView.appearance.borderRadius = 0.2
I Hope This Will Help.

How could I exclude the text from UITextField to be transparent in terms of alpha?

I have created a uitextfield setted the alpha to 0.2, the problem is I can't find how I could set the alpha opacity only to be applied to the background of the UITextField, not also to the text that is inside the UItextField.
Snippet of my code:
self.emailInputField.text = "Enter your Email/Username"
self.passwordEmailInputField.text = "Enter your Password"
self.passwordEmailInputField.backgroundColor = .white
self.emailInputField.backgroundColor = .white
self.passwordEmailInputField.alpha = 0.1
self.emailInputField.alpha = 0.1
self.passwordEmailInputField.textColor = .gray
self.passwordEmailInputField.textColor = .gray
self.view.addSubview(self.emailInputField)
self.view.addSubview(self.passwordEmailInputField)
To extend the comment above: you should not set the alpha of the field itself to 0.1 if your intent is to only change the background color. Instead, initialize the backgroundColor property with alpha:
self.passwordEmailInputField.backgroundColor = .white.withAlphaComponent(0.1)
self.emailInputField.backgroundColor = .white.withAlphaComponent(0.1)

In iOS 13 UITabBarItem's standardAppearance is applied to all other items

I'm trying to do a simple thing on iOS 13 - the last tab bar item should always be displayed in a different color.
I tried to use the new UITabBarItem.standardAppearance member. Here are my codes:
// first, set the default colors for the whole tab bar
let color = Style.Color.tabItem
let text = [NSAttributedString.Key.foregroundColor: color]
let selectedColor = Style.Color.tabItemSelected
let selectedText = [NSAttributedString.Key.foregroundColor: selectedColor]
let barAppearance = UITabBarItemAppearance()
barAppearance.normal.iconColor = color
barAppearance.disabled.iconColor = color
barAppearance.selected.iconColor = selectedColor
barAppearance.focused.iconColor = selectedColor
barAppearance.normal.titleTextAttributes = text
barAppearance.disabled.titleTextAttributes = text
barAppearance.selected.titleTextAttributes = selectedText
barAppearance.focused.titleTextAttributes = selectedText
tabBar.standardAppearance.stackedLayoutAppearance = barAppearance
tabBar.standardAppearance.inlineLayoutAppearance = barAppearance
tabBar.standardAppearance.compactInlineLayoutAppearance = barAppearance
tabBar.standardAppearance.backgroundColor = Style.Color.tabBar
// now, for the last item set special colors
if let lastItem = tabBar.items?.last {
let specialColor = Style.Color.tabItemSpecial
let specialText = [NSAttributedString.Key.foregroundColor: specialColor]
let specialSelectedColor = Style.Color.tabItemSpecialSelected
let specialSelectedText = [NSAttributedString.Key.foregroundColor: specialSelectedColor]
let itemAppearance = UITabBarItemAppearance()
itemAppearance.normal.iconColor = specialColor
itemAppearance.disabled.iconColor = specialColor
itemAppearance.selected.iconColor = specialSelectedColor
itemAppearance.focused.iconColor = specialSelectedColor
itemAppearance.normal.titleTextAttributes = specialText
itemAppearance.disabled.titleTextAttributes = specialText
itemAppearance.selected.titleTextAttributes = specialSelectedText
itemAppearance.focused.titleTextAttributes = specialSelectedText
let itemBarAppearance = UITabBarAppearance()
itemBarAppearance.stackedLayoutAppearance = itemAppearance
itemBarAppearance.inlineLayoutAppearance = itemAppearance
itemBarAppearance.compactInlineLayoutAppearance = itemAppearance
itemBarAppearance.backgroundColor = Style.Color.tabBar
lastItem.standardAppearance = itemBarAppearance
}
Expected behavior:
All the tab items are ALWAYS shown in tabItem/tabItemSelected colors, the last tab item is ALWAYS shown in tabItemSpecial/tabItemSpecialSelected color.
Actual behavior:
When any of the items is selected except the last one - all the tabs items are shown in tabItem/tabItemSelected, including the last one!
When I select the last tab bar item, it's standardAppearance style is applied TO ALL the other tab bar items too! So all of them use tabItemSpecial/tabItemSpecialSelected color scheme.
Am I doing something wrong? Or maybe I misunderstood the new APIs and there is no way to have one tab bar item to always have a different color?
This is the expected behavior. You aren't customizing how a specific tab bar item looks, you are customizing how the tab bar appears when that item is the currently selected one.

Wrapping text on TitleLabel and DetailLabel - Material Card

I am using CosmicMind - Material Framework to create a Card. titleLabel and DetailLabel do not wrap to a new line.
My question is: What do I need to do to accomplish such task and is it supposed to be automatically adjusted by the framework?
This is what I have so far:
let card = Card()
var heartIcon = IconButton()
heartIcon = IconButton(image: Icon.favoriteBorder, tintColor: Color.red.base)
//Title Bar
let toolbar = Toolbar(rightViews: [heartIcon])
toolbar.title = cardData.cardTitleText
toolbar.titleLabel.textAlignment = .left
toolbar.titleLabel.numberOfLines = 0
toolbar.detail = "Company: " + cardData.cardTitleSubtitle
toolbar.detailLabel.font = RobotoFont.regular(with: 14)
toolbar.detailLabel.textColor = Color.grey.base
toolbar.detailLabel.textAlignment = .left
toolbar.detailLabel.numberOfLines = 0
And this is my output:
Update:
I managed to achieve what I wanted by increasing the size of the toolbar frame.
toolbar.frame = CGRect(x:0,y:0,width: view.frame.width,height: 100)
My goal was to at least show 2 lines of text.
Thanks!
I have no experience with the CosmicMind framework but usually, the label.numberOfLines property defines the maximum number of lines that the label text can have. You can set it to 2 instead of 0 and it should wrap.

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.

Resources