Tabelview rows not showing(because of wrong constraints) in swift - swift

this is the cell design design img
for pic
width = height = 40, top = 15, leading = 15
here for name rose d i have given constraint
width = 60, top = 15, leading = 10
for place a bid on the request label
top = 15, leading = 5
for trip for few days label
top = 15, leading = 5, trailing >= 20
for dummy caption shoe here label
trailing = 20, leading to image = 10, top to rose d = 5 and label lines = 0
for 46 mins ago label
top and leading to dummy caption.. lable = 10, trailing >= 20
i don't want to give row fixed height.. because dummy caption label may increase..
now rows not showing in tableview.. only if i give fixed height then only showing
here where i go wrong with constraints.. so i not getting rows in tableview, please guide me
if i give bottom constraint to lowest label and if i add more text to middle label then coming like this design and constraint of middle label img

You have not set any bottom constraints, therefore the layout doesn't know how to anchor the bottom of the cell to your UI elements.
Set constraints from the lowest element to the bottom of the cell's content view, or more flexibly set greater or equal to constraints from all lower elements so you don't need to worry about the number of lines in your labels.
However, I think a better approach would be to use a single label with an attributed string to provide the colouring. This will be more flexible and ensure the spacing between words looks natural.

Related

how to make horizontal padding in iOS danielgindi charts

I'm using the ios-charts library and I would like to add some horizontal padding to my line charts so that the line does not start immediately at the border of the graph.
This is my current chart:
but I would like the blue line to have some padding as shown below. The rest should remain as it is. The reference gray lines should still take the entire width as they currently do.
I found it. This "padding" is actually ruled by the chart.xAxis.axisMinimum and chart.xAxis.axisMaximum. Those values are automatically set to the data min x and max x.
So if I want a left padding I just have to set a chart.xAxis.axisMinimum
In my case, I want around 10% of the x values to be padded, so I calculate it as
// dates is an array of Date representing my x values
if let maxX = dates
.map(\.timeIntervalSince1970)
.max(),
let minX = dates
.map(\.timeIntervalSince1970)
.min() {
let spanX = maxX - minX
let padding = spanX * 0.1
let axisMinimum = minX - padding
// set the left padding
chart.xAxis.axisMinimum = axisMinimum
}

Label text truncated after increasing font size

I followed the procedures in this question, and also tried setting individual text object with larger fonts. Here is my sample code:
hf = figure;
set(hf, 'DefaultAxesFontSize', 14)
hx = axes('Parent',hf);
[hx,hp1,hp2] = plotyy(hx, rand(10,1),rand(10,1),rand(10,1),rand(10,1),'scatter');
hlx = xlabel(hx(1), 'Only half of this line show up');
hl1 = ylabel(hx(1), 'Not usually truncated but less border');
hl2 = ylabel(hx(2), 'Only part of this line show up');
ht = title(hx(1), 'Too close to border');
As can be seen in the picture, the labels get truncated by the border of the figure. I have to drag the figure to very large - contrary to desired - in order to reveal all text.
How can I automatically set the text box according to the text font size, so that even for small graphs they don't get cut?
I know I can do it manually by setting Position of the axes but it's kind of manual and guess-and-try. Is there any automatic way to calculate the margins?
One thing that can be done is to calculate increased margin according to new text font size. Assume we know Matlab's default font size is 10, or otherwise get it by get(hf,'DefaultAxesFontSize').
Then get the relative position of the axes by get(hx, 'Position'), which gives four percentage values. First two define left and bottom margin. Since it's for the labels, increasing the font size from 10 to 14 means the text box should grow by 1.4 times. The next two numbers define the size of the axis. Since text boxes on both sides grow by 1.4 times, assuming original size being x, then new size is 1-[(1-x)*1.4] = 1.4x - 0.4.
Suggested workaround:
hf = figure;
set(hf, 'DefaultAxesFontSize', 14)
hx = axes('Parent',hf);
set(hx, 'Position', [1.4 1.4 1.4 1.4].*get(hx, 'Position')+ [0 0 -.4 -.4])
[hx,hp1,hp2] = plotyy(hx, rand(10,1),rand(10,1),rand(10,1),rand(10,1),'scatter');
hlx = xlabel(hx(1), 'Only half of this line show up');
hl1 = ylabel(hx(1), 'Not usually truncated but less border');
hl2 = ylabel(hx(2), 'Only part of this line show up');
ht = title(hx(1), 'Too close to border');
You may replace the manually entered number 1.4 with the ratio between newly assigned (bigger, hopefully) font size and the original size which is 10.

Detect textfield overflowing

I'd like to be able to detect when a UITextfield overflows it bounds.
I want to detect Horizontal overflow (since there is only 1 line).
I was thinking about counting the amount of characters and multiplying that with a default value for the letter width and see if that fits inside the textfield bounds but that wouldn't work due too the letter having different widths.
I am aware of adjustsFontSizeToFitWidth but I want to increase the width of the textfield instead of decreasing the font size.
Here is the code which first calculates the size of the text and then compares it to the label size:
let textSize: CGSize = self.label.text!.sizeWithAttributes([NSFontAttributeName: self.label.font])
let isOverflowing: Bool = textSize.width > self.label.frame.size.width

How to shrink the size of the text inside a label

Im trying to get text to fill the entire bounds of a label no matter how long or short the text string is. I want the largest possible font size without any truncation or clipping.
I set up my label like so:
var messageTitle = TTTAttributedLabel()
messageTitle.setTranslatesAutoresizingMaskIntoConstraints(false)
messageTitle.font = AppTheme.largeMessageFont()
messageTitle.verticalAlignment = .Bottom
messageTitle.numberOfLines = 0
messageTitle.adjustsFontSizeToFitWidth = true
messageTitle.minimumScaleFactor = 0.2
And set the various constraints to set the size of the label to be 250 x 250.
I'm pretty sure this used to work. The label text now gets truncated if it is long when it should be shrinking the size of the text
You can set the font into maximum font size then add this attribut
theLabel.adjustsFontSizeToFitWidth = true
theLabel.minimumScaleFactor = 0.5 //this is the minimum scale factor, set it as small as you want

google charts: timeline: dynamic height with scalebar position

Thanks for viewing and answering.
I am using Google Charts (TimeLine) to display information from database.
But the Google Chart reference only provide setting fix height for the chart.
Whereas I would like to change chart height based on the number of rows I get from data.
So I made the code:
var graph = $('#chart_timeLine').children()[0].children[0].children[1];
$(graph).css('height',graph.scrollHeight);
$(graph).css('overflow-y','auto');
Now the chart don't have a vertical scrollbar and I am satisfied.
But I found that the scalebar, which shows the the scale of timeline chart is missing.(It is actually hiding under the chart, instead of showing up at the bottom of the chart).
So then I changed scalebar's position to absolute and set it to the bottom of my chart.
Then it is ugly because it has a height of 200px, while the scale is at the bottom of that 200px, leaving a huge blank between my chart and the scale.
Is there a fix for that?
Thank you.
Instead of messing with the internal workings of the chart, set the height based on the number of rows of data in the DataTable:
// set a padding value to cover the height of title and axis values
var paddingHeight = 40;
// set the height to be covered by the rows
var rowHeight = data.getNumberOfRows() * 15;
// set the total chart height
var chartHeight = rowHeight + paddingHeight;
and then in the Timeline's options, set the height:
height: chartHeight
I tried the answer, but it did not work for me. The way I got it to work for me was this:
// Calculate height
var rowHeight = 41;
var chartHeight = dataTable.getNumberOfRows() * rowHeight + 50;
var options = {
height: chartHeight
}
The + 1 to the getNumberOfRows() is for the X-axis text.
$.ajax({
...
success: function(jsonData){
...
var options = {
height: (jsonData.length * 40) + 80,
timeline: { colorByRowLabel: true }
};
chart.draw(dataTable, options);
}
});
As far as I can tell its:
30px height for each bar
10px padding for each group.
60px for the Series.
So for a 9 bar Group = (30 * 9) + 10 = 280px
Chart Height = 280px + 60px
If you are Grouping Rows you will need to determine if your date ranges overlap with any others in that group.
Google does this by:
Getting the Group items IN START DATE ORDER
Creating an empty array of Group Display Rows
For each Group Item:
For each Display Row
If Item fits in Row...
Add it to existing Display Row
Next
If No existing Display row found
Add New Display Row
Next