How to shrink the size of the text inside a label - swift

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

Related

Tabelview rows not showing(because of wrong constraints) in 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.

How to draw multi size using vispy?

I use following code to draw a point cloud in vispy
# init
view = vispy.sence.widgets.ViewBox()
vis = visuals.Markers()
view.add(vis)
# updata data
vis.set_data(data,
face_color = color,
edge_color=color,
size = 1
)
vispy.app.run
As you can see, I could set the fixed point size for whole data.
How can I set multi size in one data?
You should be able to set the size with a numpy array (one element for every marker point):
https://github.com/vispy/vispy/blob/932d6e499791a423822513549ebd825601345c85/vispy/visuals/markers.py#L517-L518
size : float or array
The symbol size in px.

ActiveReports Change Image size at runtime

I have an image that is 300px width and has to be set at runtime. At design time, the image is a different size and depending on a flag, the image has to be changed. How do I set the image width in C#/VB.NET.
I cast the object as a Picture. The Width property only takes a SINGLE value and presume its inches. How do I tell the picture control that I'm passing in is the pixel size not inches?
Here's an example of how you can set the size in pixels, convert it to inches (as the GrapeCity Team suggests), and apply it to your picture based on a conditional variable:
The following code is added in the Script section of your report:
Sub Detail_Format
Dim intSizeInPixels As Integer = 300
Dim dblSizeInInches as Double = intSizeInPixels / 96
Dim mfFlag As Boolean = True
If mfFlag Then
Picture1.Width = dblSizeInInches
End If
End Sub

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