I have a list view that stretch to device width that shows a list of names, I need to make the label fit the total width, just like autofit. So if its a short name it should have max font to fit to view width or if its a long name the font size should decrease to fit the view width. Blackberry 10.2 has a autofit property on label that does this but I need it to support from 10.0. So is there any other alternative to do this?
This is my current definition of the label
Label {
id: myLabel
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Center
textStyle {
base: tsLabel.style
}
TextStyleDefinition {
id: tsLabel
base: SystemDefaults.TextStyles.BodyText
fontSize: FontSize.PointValue
fontSizeValue:14
color: Color.White
fontWeight: FontWeight.Bold
}
Related
I'm trying to align texts of different sizes at the top so that they stay aligned when the Dynamic Type size changes.
import SwiftUI
struct ContentView: View {
var body: some View {
HStack(alignment: .center, spacing: 0) {
Text("$")
.font(Font.custom("Helvetica", size: 24, relativeTo: .footnote))
.baselineOffset(7)
Text("123")
.font(Font.custom("Helvetica", size: 36, relativeTo: .footnote))
Text("45")
.font(Font.custom("Helvetica", size: 24, relativeTo: .footnote))
.baselineOffset(7)
}
}
}
This is aligned at top at
Regular Size
But it loses the top alignment as the Dynamic Type gets bigger: Dynamic Type Size ExtraExtraExtraLarge
Any ideas on how to keep them aligned at top even as the Dynamic Type size changes?
Any ideas on how to keep them aligned at top even as the Dynamic Type size changes?
I never needed this kind of configuration but your question arose my curiosity. 🤔
(I keep the same context you provided: 3 Text elements with the same text styles/font and two of them having the same font size)
How can I align two Text elements on top with different font sizes? 😵💫
I took a look at the font metrics to understand the returned values.
If these elements are aligned on top in a HStack view, it's the top edge that's concerned, not the letters nor the numbers inside.
So, I have to move vertically the biggest one to make its top content aligned to the smallest one.
To reach this goal, I used the alignmentGuide method that returns a view modified with respect to its horizontal alignment according to the computation performed in the method's closure by using the ascender and capHeight metrics difference.
How do I take into account the Dynamic Type feature in this implementation? 😰
The initial font sizes can be adapted to the user's preferences by using the dynamic property wrapper #ScaledMetrics that scales a numeric value.👍
I implement this information with Xcode 13.4 and iOS 15:🤓
import SwiftUI
import Foundation
struct ContentView: View {
#ScaledMetric(relativeTo: .footnote) var sizeMax: CGFloat=60
#ScaledMetric(relativeTo: .footnote) var sizeMin: CGFloat=24
var body: some View {
HStack(alignment: .top){
Text("$1&")
.font(Font.custom("Helvetica", size: 24,
relativeTo: .footnote))
.background(Color.blue)
Text("a2A")
.font(Font.custom("Helvetica", size: 60,
relativeTo: .footnote))
.alignmentGuide(VerticalAlignment.top){ d in
let customFontDescriptor = UIFontDescriptor.init(fontAttributes: [
UIFontDescriptor.AttributeName.family: "Helvetica",
UIFontDescriptor.AttributeName.textStyle:"footnote"
])
// Values for the font with min size.
let fontMin=UIFont(descriptor: customFontDescriptor,
size: sizeMin)
let ascMin = fontMin.ascender
let capHeightMin = fontMin.capHeight
// Values for the font with max size.
let fontMax=UIFont(descriptor: customFontDescriptor,
size: sizeMax)
let ascMax = fontMax.ascender
let capHeightMax = fontMax.capHeight
return abs((ascMax-capHeightMax)-(ascMin-capHeightMin))
}
.background(Color.gray)
Text("b3B")
.font(Font.custom("Helvetica", size: 24,
relativeTo: .footnote))
.background(Color.red)
}
}
}
Following this rationale, I get the following result to keep texts of different sizes aligned at top as the dynamic type size changes. 🎉🥳🎊
Don't hesitate to adapt this code snippet that fits the example you provided and that's definitely not generic. 😉
I have a view with a navigation bar, some other views with fixed height on the top and some other views with fixed height on the bottom (including a tab bar). What I'm trying to achieve is to constrain content to fix the remaining space in the center of the screen without using a scroll view.
The app needs to run on iPhone SE (1st generation) which is the model with the minimum available height. This content includes some multiline text and some buttons with multiline text labels so the idea is to scale the font and the buttons height.
I tried to compute the difference between the screen height and the top and bottom content, but some element (e.g. the padding) are dynamically computed by the system and I cannot assume to be fixed.
Here is the model of my view.
var body: some View {
VStack {
// Top content with fixed size
VStack {
Text("Here it's some multiline text")
Button(action: { }, label { Text("Some other multiline text label") }
// Other buttons
Button(action: { }, label: { Text("Last multiline text label") }
}
/*
What my frame height should be?
.frame(height: ?)
*/
// Bottom content with fixed size
}
}
I'm trying to resize the range selector. i'm able to change button sizes but they are coming close to each other. how can i increase the font size without increasing the space between buttons. Thanks in advance.
You can control the rangeSelector buttons by buttonSpacing and buttonTheme options. Setting a fixed width should be enough in your case:
rangeSelector: {
buttonSpacing: 5,
buttonTheme: {
width: 30,
style: {
fontSize: 16
}
}
}
Live demo: http://jsfiddle.net/BlackLabel/5f6aro7t/
API Reference: https://api.highcharts.com/highstock/rangeSelector.buttonSpacing
I have a chart with varying heights based on a parameter, due to which the y-axis title gets cut off at the top when height becomes less than the title length.
The highchart api at http://api.highcharts.com/highcharts/yAxis.title specifies a style property where CSS styles for the title can be given, but the javascript wordWrap:'break-word' isn't working here.
My question is - Is there any property that can wrap the title of the the y-axis in such a case ?
Note: I searched SO and found a question - Highcharts Y-axis title text length is more than chart's height, but this doesn't answer my case as I don't have a static title and cannot have a tag to force the line break.
Just add fixed width and step in the style:
title: {
enabled: true,
text: 'very long title text here that will get cut off at the top when height becomes less than the length of the title',
style: {
font: 'bold 10pt "Arial Narrow"',
color: 'rgb(0,0,0)',
wordWrap:'break-word',
// Add these
width : "200px"
}
}
your Fiddle updated here
I need to draw a bar chart and need to set width and height for the container div (as there is only that amount of space I can use)
However, when I set height and width, in some cases, highchart will not draw some of the bar labels, even though I think there are places to draw them. Can someone explain this or maybe provide a workaround (without removing height)?
The jsfiddle is http://jsfiddle.net/daxu/md2zk/68/
labels: {
style: {
color: 'black',
fontFamily: 'DINPro',
fontSize: '7.8409px',
fontWeight: 'normal'
},
formatter: function () {
return this.value;
}
}
At the beginning, remove datalabels configuration per each point and use common options. There, you can disable hiding labels by crop option.
Example: http://jsfiddle.net/md2zk/70/