I have multiple ButtonFields in a VerticalFieldManager. By default the width of each button depends on the text it contains.
I would like all the buttons to be of the same width - equal to the width of the widest button.
Take a look at the BlackBerry Developers Knowledge Base:
How to - Implement advanced buttons, fields, and managers
Last Updated: 12 February 2010
Article Number: DB-00796
You are probably looking for the VerticalButtonFieldSet!
Step 1 - Extend the VerticalFieldManager class, and make the constructor take in a bunch of Strings that you want to put end each button.
Step 2 - Find the longest of String out of the Strings passed into the manager.
Step 3 - create the button for the longest string
Step 4 - create all other buttons, and set their width to the same as the 1st (see setExtent)
Step 5 - add the buttons to the manager in the order you want them to appear
FIN
Have you tried using the Field.USE_ALL_WIDTH style flag?
Try ButtonField buttonField = new ButtonField("ButtonText", Field.USE_ALL_WIDTH);
and that should use the full width.
If that doesn't work, try extending ButtonField, overriding layout and calling setExtent(width, height) with the width and height that you want.
Related
I Have a view like so:
And I am trying to add constraints so the text fields are side by side so the auto looks the same no matter the device width, how would I do that?
I have tried the following for all 6 of them:
But it ends up looking like this:
What am I doing wrong?
Ctrl drag from the description TextField to vendor TextField and select Equal Widths from popup
You can also use a vertical stackView where each row is a horizontal 1 with distribution set to Equal spacing and drag the text fields to it that will be more easier
Well, let's look at what we know about the horizontal axis (I assume you've got the vertical axis taken care of). There are two text fields; call them Left and Right. We know these things:
Where Left's leading edge must be
Where Right's trailing edge must be
The distance between Left's trailing and edge and Right's leading edge
The relationship between Left's width and Right's width, i.e. they are equal
Ta-daa:
(A UIStackView would construct these same constraints for you, but in a simple situation like this it's probably more trouble than it's worth.)
There are many ways to do it
I give you two but recommend the first one in your case.
First :
Define a constraint by draging one of your UITextFiled to the other one and set it to “Equal Widths”
You may also be able to define a percentage for each (60-40%) if you like.
Second :
Define a constraint like above (draging) And define a relative ratio (0.5) for UITextField width against its superview. Do it for the other one. You need to go to Object Inspector Tab and change the values if needed (so this requires two constraints, one for each UITextField as each of them are relative to the their superview) this is also a little bit slower than the first approach since margins should be defined with priority.
I am using JSQMessagesViewController and I created a custom cell according to this answer.
How to add custom view to JSQMessagesViewController cell so that it includes one view with some buttons and text view?
Now I am struggling to set auto layout constrains correctly. So, the message bubble not display correctly. Please help me set the constraints correctly
So lets take a stab at this. So first things that I would do it set a constraint for the first button to be equal hight of the other. You can accomplish a couple of ways but I will only describe one here for brevity. You can do hold the control button on your computer and select button1 and drag to button2. This will present you with a couple of options that look like this.
You want to select Equal Heights this will make it so both your buttons have the same hight. Then you will want to give it a hight. Once again hold down the control button on your keyboard but this time click button1 drag and release within button1. you should get something along the lines of this.
If you do not get the desired options try dragging in a diagonal direction. Xcode is tying to guess what constraints you want based on the direction of your drag. I.E. If you drag vertically you should get the Height option.
Then you can go to the properties inspector on the right and set a number for how high you would like. Text is normally around 12pt so I would go with about 30pt or more for the hight of a button. Then add a constraint for spacing between them and leading and trailing to the containing view or you could give them a standard width and center them in the view. Which ever fits best for you.
Edit:
You should also adjust the bubble size calculation.
It can be found in the JSQMessagesBubblesSizeCalculator class.
Eg: In the
- (CGSize)messageBubbleSizeForMessageData {
if([messageData isOptionMessage]){
// add button height also (In this case i have set constant 200. But we have to calculate the actual button heights instead)
finalSize = CGSizeMake(finalWidth, stringSize.height + verticalInsets + 200)
} else {
finalSize = CGSizeMake(finalWidth, stringSize.height + verticalInsets)
}
}
Let me know if you need any more help and keep up the good work. 👍🏼 🚜
So I am wanting to create a Scrollview with a list of labels. I am having a super hard time with the constraints and what not. It is obviously nothing like adding labels to a simple UIView.
What i need is one label in the top left corner, about 40% width from parent view with a top and left border of 10. Then i need a second label right next to it also with a 40% width and a top and right border of 10. After doing this i will continue creating labels under each other in the same sequence. All with borders of 10.
(P.S. I know labels have a set height value but i have been giving them values of 0.05% height of parent view just for organizing reasons.)
Now, normally when adding to a normal view i would match the parent width and height then go to the identity inspector and under the sizes-equalwidthsconstraint-multiplier set it to 0.4 and height etc. Then I would go to the pin and add the constraints top: 10 and left: 10. By that time i would be golden with the first label! However it doesnt work that way with scrollviews. I keep getting red lines every where and a caution alert saying "Scrollable content size is ambiguous for "Scroll View"".
(P.S. I have however been able to successfully create the first label, with red lines though, but when creating the second label i can never get it to line up right.)
If you dont know how to do it through storyboard and should do it programmatically then how would i do that? Swift please, always.
for example:
make: Chevrolet
model: Silverado
year: 2016
color: Pearl White
so on and so forth....
its basically a list of non editable text..
i was wanting to go for that look.
Please help, thank you!
Use UITableView's. Apple has designed UITableView for these kinds of problem statements.
Here is a good place to start.
http://code.tutsplus.com/tutorials/ios-from-scratch-with-swift-table-view-basics--cms-25160
And for your case, you need to use Custom UITableViewCell for your specific problem
I have been recently getting into iOS development, and I'm trying to build something that looks (very roughly) like this: http://falkendev.com/downloads/ios-sample.png
Basically, it's a page that shows simple text -- large header text that may span multiple lines, a separator line, and then smaller descriptive text that may be a variable length. This text does not need to be editable. I'm working using interface builder, but I imagine that what I want done may need to be done programmatically?
Two questions:
-- How do I go about creating these text fields so that they adjust their height based on the content? I'm assuming I would be using a standard "text" field for each, make them not editable, and then programmatically change their height? And then based on the height of the various text fields, I would need to adjust the positioning of the text fields and the divider line between them?
-- How do I go about making the page scrollable? It's possible that the descriptive text will be long and would extend off the edge of the screen. I would want the whole page to be scrollable, not just the descriptive text section. I'm assuming I would place all my elements within a scroll view... but currently when I do that and view it, the view just gets centered (cutting off both the top and the bottom) and I can't scroll it at all.
Thanks for any help!
set the scrollview content size to greater than its actual size to
make it scrollable like this :
scrollView.contentSize = CGSizeMake(YourWidth ,YourHEight ); // Here you can change either of height and width to make it more scrollable in that direction.
You can use UITextView object to have a scrollable text field...
which can scroll to show additional text..just set its editing
property to NO.
Otherwise to dynamically update label height yourself...use
NSString sizeWithFont method
I have a simple login form on a TTTableView, in which I use TTTableControlItem with UITextFields.
I have two fields, Email & Password. Since the UILabel's width determined by the text, the two textfields aren't aligned vertically to the same line and it looks bad.
How do I control the width of the caption inside?
Is there another way to achieve this without subclassing/finding the labels/controls and move them after render?
Thanks.
You'll have to subclass TTTableControlCell with your own custom cell and override the function
- (void)layoutSubviews;
to layout the contents the way you want to.
Also don't forget to map TTTableControlItem to your new custom cell subclass in your data source (in the
- (Class)tableView:(UITableView*)tableView cellClassForObject:(id) object;
method)
I had the same problem and I chose to just set the text field to align the text on the right. I didn't like the amount of padding so I modified TTTableControlCell to cut back the width of the text field.