I have Label in my UIView which continuously changes values in between 80(min) to 475(Max) now I have run the progress bar status with respect to max and min value of label continuously. below where the code i have tried till now
if ampsMaxValue <= 80
{
ampsMaxValue = 80
ampsLabel.text = String(ampsMaxValue)
ampsprogressBar.progress = Float(0)
return
}
ampsMaxValue = ampsMaxValue - 1
ampsLabel.textColor = UIColor.white
ampsprogressBar.tintColor = UIColor.red
ampsLabel.text = String(ampsMaxValue)
v -= 0.1
ampsprogressBar.progress = Float(v)
}else{
if ampsMaxValue >= 475
{
ampsMaxValue = 475
ampsLabel.text = String(ampsMaxValue)
ampsprogressBar.progress = Float(1)
return;
}
ampsMaxValue = ampsMaxValue + 1
ampsLabel.textColor = UIColor.white
ampsprogressBar.tintColor = UIColor.red
ampsLabel.text = String(ampsMaxValue)
v += 0.1
ampsprogressBar.progress = Float(v)
}
I was able show the increased and decreased value by 0.1, but not solved it. need info about how calculate the exact increased and decreased value for the progress bar with respect to the label max an min value.
Try:
v = (ampsMaxValue - 80) / (475 - 80)
Related
I make a custom numbering label, everything works great. the problem is when the number of entries is less than X-axis maximum, the chart doesn't show any lines.
lineChart.data = data
let leftAxis = lineChart.leftAxis
//set constant label range
leftAxis.forceLabelsEnabled = true
leftAxis.labelCount = 4
leftAxis.axisMinimum = 0
leftAxis.axisMaximum = 4.5
leftAxis.granularity = 1
leftAxis.axisLineWidth = 0
leftAxis.valueFormatter = YAxisData()
//x axis label
let bottomAxis = lineChart.xAxis
bottomAxis.axisMinimum = 1
bottomAxis.axisMaximum = 7.0
bottomAxis.labelCount = 7
bottomAxis.forceLabelsEnabled = true
bottomAxis.granularity = 1
bottomAxis.axisLineWidth = 0
bottomAxis.valueFormatter = XAxisData()
bottomAxis.labelHeight = 30
if I changed the number of entries to 7, it works fine.
I want a way to show all x labels even if the number of entries is less than 7!
I'm plotting sunrise/sunset against time, so time goes along the X axis with iOS Charts (Daniel Gindi).
If I display the x labels as numbers they manifest correctly: If I swap them over to text (Jan - Dec) only Jan shows up???
Associated iOS Chart code:
// Setup X Axis
lineChartView.xAxis.axisMinimum = 0
lineChartView.xAxis.axisMaximum = 366
lineChartView.xAxis.granularityEnabled = true
lineChartView.xAxis.granularity = 30
lineChartView.xAxis.labelCount = 12
lineChartView.xAxis.axisLineWidth = 2
lineChartView.xAxis.axisLineColor = .black
lineChartView.xAxis.centerAxisLabelsEnabled = true
If I swap it over to literals then I only get Jan. All the values are populated. Any ideas?
Code: (n.b. putting labelCount before IndexAxisValueFormatter(values:months) makes no difference.)
// Setup X Axis
let months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"]
lineChartView.xAxis.axisMinimum = 0
lineChartView.xAxis.axisMaximum = 366
lineChartView.xAxis.granularityEnabled = true
lineChartView.xAxis.granularity = 30
lineChartView.xAxis.labelCount = 12
lineChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
lineChartView.xAxis.axisLineWidth = 2
lineChartView.xAxis.axisLineColor = .black
lineChartView.xAxis.centerAxisLabelsEnabled = true
I am new to Kivy and this is my first time trying to create a scrollView.
I am trying to do a 'Splitwise' ripoff where you can create expenses and let the app figure out who should pay who etc.
I am trying to create a method that opens a popup with all members and their balances as well as a button with the text 'Settle up'. Underneath the balances should be a list of all the registered debts, and you should be able to scroll down to see them all. The popup should also contain a 'Cancel'-button.
My problem is that my code doesn't enable scrolling, and also squishes together the content in the pop up. See picture.
All help highly appreciated!
See (messy) code below:
sbl_ret = GridLayout(cols = 1)
sbl_balances = GridLayout(cols = 3)
sbl_balances.add_widget(Label())
sbl_balances.add_widget(Label(text = 'Balances', font_size = '20sp', size_hint = (1,.2), color = backgroundColor, bold = True))
sbl_balances.add_widget(Label())
for member in self.members:
sbl_balances.add_widget(Label(text = member.getName(), font_size = 40, size_hint_y = None, height = 60))
sbl_balances.add_widget(Label(text = str(round(member.getBalance())) + ' kr', font_size = 40, size_hint_y = None, height = 60))
sbl2 = BoxLayout(orientation = 'vertical')
sbl2.add_widget(Label(size_hint = (1,.2)))
btn = Button(text = 'Settle up', background_color = buttonColor, bold = True, size_hint_y = None, height = 60)
btn.bind(on_press = lambda member: self.settleUp())
sbl2.add_widget(btn)
sbl2.add_widget(Label(size_hint = (1,.2)))
sbl_balances.add_widget(sbl2)
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(text = 'Debts', font_size = '20sp', color = backgroundColor, bold = True))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
for member in self.members:
for debt in member.getDebtList():
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(size_hint_y = None, height = 60, text = debt.getToWhom().getName() + ' lent ' + str(debt.getAmount()) + ' SEK to ' + debt.getFromWhom().getName() + ' for ' + debt.getDescription(), font_size = 40))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.bind(minimum_height=sbl_balances.setter('height'))
sbl3 = BoxLayout(size_hint = (1,.15))
sbl3.add_widget(Label(size_hint = (.2,1)))
b = Button(text = 'Cancel', background_color = entryColor, size_hint_y = None, height = 150)
b.bind(on_press = lambda x: self.balanceDialog.dismiss())
sbl3.add_widget(b)
sbl3.add_widget(Label(size_hint = (.2,1)))
sv = ScrollView(do_scroll_x = False)
sv.add_widget(sbl_balances)
sbl_ret.add_widget(sv)
sbl_ret.add_widget(sbl3)
self.balanceDialog = Popup(title = 'Group view', content = sbl_ret, title_align = 'center',
title_color = backgroundColor, background_color = [0,0,0,.7], separator_height = 0, title_size = '28sp')
self.balanceDialog.open()
'''
Try adding size_hint_y=None to your code creating the GridLayout:
sbl_balances = GridLayout(cols = 3, size_hint_y=None)
See the documentation.
I followed this video for study Collection View (https://www.youtube.com/watch?v=jQ8EUsQZJ5g)
And I wrote code like this :
if ( CollectionViewFlowLayout == nil ){
let numberOfItemsForRow : CGFloat = 2
let UpDownSpace : CGFloat = 5
let LeftRightSpace : CGFloat = 5
//CollectionViewFlowLayout은 delgate 처럼 소재지를 수정하고 꾸밀 수 있는 것이다.
CollectionViewFlowLayout = UICollectionViewFlowLayout()
//이건 margin의 크기를 정해주는 것이다.
CollectionViewFlowLayout?.sectionInset = UIEdgeInsets.zero
//이건 화면을 수직으로 내릴 것이냐, 수평으로 스크롤 할것이냐를 정해준다.
CollectionViewFlowLayout?.scrollDirection = .vertical
//소재지의 위 아래의 간격을 정해준다.
CollectionViewFlowLayout?.minimumLineSpacing = UpDownSpace
//같은 줄에 있는 소재지의 오른쪽 왼쪽 사이의 간격을 정해준다.
CollectionViewFlowLayout?.minimumInteritemSpacing = LeftRightSpace
let total = (LeftRightSpace * (numberOfItemsForRow - 1))
let width = (CollectionView.frame.width - total) / numberOfItemsForRow
let height = width
//itemsize : 소재지의 크기를 정 할 수 있다
CollectionViewFlowLayout?.itemSize = CGSize(width: width, height: height)
CollectionView.setCollectionViewLayout(CollectionViewFlowLayout!, animated: true)
}
But when I use simulator with iPhone 8, It make error
Other things are Good! without iPhone 8
enter image description here
I think your total should be calculated as:
let total = LeftRightSpace * (numberOfItemsForRow + 1), because you are taking away left, right and interitem spacing.
Or try calculating width as:
let width = (UIScreen.main.bounds.width - total) / numberOfItemsForRow
in code below it displays "SCORE: 100" or whatever however as the score / points change
the totals are over lapping one on top of the other and you cant read them ...
i want the old score erased / removed before displaying new score/points
ANY THOUGHTS HOW TO FIX this...this is LUA and using CORONA SDK
during my test i have sent print statements to try to troubleshoot sections
--Points is being calculated in another location
--UPDATE SCORE POINTS
local function updateScore(Points)
if WTF == 1 then
print ("SCORE: -->",Points)
--PointsText:removeSelf(PointsText)
PointsText = display.newText(Points,0,0,native.sytemFont,42)
PointsText.text = Points
PointsText.xscale = 0.5; PointsText.yscale = 0.5
PointsText:setTextColor(155,155,225)
PointsText.x = centerX * 1
PointsText.y = centerY - 150
ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
ScoreTxt:setTextColor(220,50,50)
ScoreTxt.x = display.contentCenterX
ScoreTxt.y = display.contentCenterY-100
end
end
Every time you call updateScore you're creating a new text object. This code ensures you only create the text once.
local function updateScore(Points)
if PointsText == nil then
PointsText = display.newText(Points,0,0,native.sytemFont,42)
end
PointsText.text = Points
PointsText.xscale = 0.5; PointsText.yscale = 0.5
PointsText:setTextColor(155,155,225)
PointsText.x = centerX * 1
PointsText.y = centerY - 150
ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
ScoreTxt:setTextColor(220,50,50)
ScoreTxt.x = display.contentCenterX
ScoreTxt.y = display.contentCenterY-100
end
You could also do:
local function updateScore(Points)
if PointsText then
PointsText:removeSelf()
end
PointsText = display.newText(Points,0,0,native.systemFont,42)
PointsText.text = Points
PointsText.xscale = 0.5; PointsText.yscale = 0.5
PointsText:setTextColor(155,155,225)
PointsText.x = centerX * 1
PointsText.y = centerY - 150
ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
ScoreTxt:setTextColor(220,50,50)
ScoreTxt.x = display.contentCenterX
ScoreTxt.y = display.contentCenterY-100
end