How to increase the space between the fields in VerticalFieldManager - blackberry

I am adding three CustomButtons in verticalFieldManager, but there is no spacing between the buttons. all are coming one after the other.

use the method setPadding(int top, int right, int bottom, int left)

you can also do it by using Field.setMargin (int Top, int Right, int Bottom, int Left) method. You may find articles on this forum debating if undocumented functions should be used or not but setMargin() has even been used in RIM's own examples so I doubt there is any problem with using it.

Related

Need an explanation of NSLayoutAttributeBaseline

Can anybody please provide a simple explanation of NSLayoutAttributeBaseline, NSLayoutAttributeFirstBaseline and NSLayoutAttributeLastBaseline? Why do we need it? What is a good example of using it? Apple's explanation of this topic doesn't seem to be clear and obvious. Can't find good examples throughout the web as well. Thanks in advance!
Baseline applies to views such as UILabel. The baseline would be the position where the bottom of uppercase letters appears. For most other views (if not all others) the baseline and the bottom are the same.
For more you can follow the thread: What is the difference between NSLayoutAttributeBaseline and NSLayoutAttributeBottom?
It is, what is it called. The baseline of the text of a view.
Imagine you have view with text inside, let's say a label. And you have another view with that, but it has a box around it (so it is taller). Aligning the top edge or the bottom edge would have the text on different heights. With this attribute, you can align the text in two views of different kinds.
Here is an example with top, bottom and baseline alignment

Create a UIView with a 0.5 height in a Storyboard [duplicate]

I want to to assign a float value to a UIButtons frame in Storyboard.
But I can only use int values. Is it discouraged to use .5 for example? because I have some buttons and I want to place them according to the original photoshop design.
for example I have a button I need to be placed at X:151 , how can I achieve that?
Do NOT use a float value. As you have rightly observed, Interface Builder prevents this; but you should not do it even in code. Just the opposite: when you assign a frame (or related component) in code, you should set it to an integral value first. (In fact, there are even functions such as CGRectIntegral to help you.)
The reason is that otherwise you can end up between pixels on the screen, and the view will not display correctly (because there is no such thing as half a pixel). Stick to whole numbers of points so that you are using whole numbers of pixels.
Do it programmatically (click here for example), I don't know the reason why storyboard prevents from using non-integer values for frame ingredients, however I do know three things:
It works programmatically. (just assign a dummy value in storyboard and overwrite it in code later on.)
Apple uses non-integer values for their native objects in iOS, for example the line separator between cells in table view is 0.5 point height.
Points are not pixels (response to the accepted answer, according to the time of writing these lines.)
First of all I was not able to find a solid reference of Not using float value on storyboard. So following a workflow/procedure to achieve float value on storyboard. Last tried with Xcode Version 7.3.1 (7D1014).
Select the view. Remove any previous constraint for the UIView if any. Then add all the constraints including the floating value. On my case it was Leading, Trailing, bottom and Height. Only Bottom have a Int value others are float. Press the "Add X Constraints" button.
Finally I have the following:
The problem is that whenever I want to edit the value, I have to remove all the previous constraints and add them again according to the new constraints.

How do I set margins to zero in a uitableviewcell?

As seen in the link below theres some margin/padding on the top, bottom, left and right part of a cell. How do I set it to zero? I tried returning CGRectMake(0,0,0,0) in the -(CGRect)layoutMargins margin of the UITableViewCell's lifecycle.
https://www.dropbox.com/s/rl95v2688k70u0j/Screenshot%202014-10-13%2003.29.08.png?dl=0
If you are using AutoLayout (which seems to be the case according to your screenshot) you can reach this be modifying the constraints (the blue lines which you see in Interface Builder). AutoLayout can be tough to deal with at the beginning, but if follows quite logical structures. If you want to get down on the nitty gritty of it and understand how it works I can recommend you this excellent video tutorial from Scotty on the topic.
Another simple way would be to turn off AutoLayout and just set the label to the same size of your cell, so your approach with CGRectMake isn't all that wrong, except that you need to keep in mind that it takes as parameters: x and y coordinates (which you want to set to 0 as you already did) but also width and height (which you also set to 0, but probably want to set equal to the cell's size).
AutoLayout can be turned off in Interface Builder by removing the checkmark in the following picture:

Add Manager to bottom of BlackBerry Screen

I am trying to create a layout as show in the image attached here:
Here are my screen components,
Screen title field
Button at the center of screen
HorizontalFieldManager containing 3 buttons docked to bottom of screen
Add banner, placed as docked below.
I have completed all of the 1, 2 and 4. I have used setStatus(Field) to place the ad banner. Also, I have customized the HorizontalFieldManager for holding 3 fields justified aligned. Now I don't know how could I place it to the bottom of screen just above the add banner, as I've already used setStatus() for the ad banner. Also, if the virtual keyboard comes up, I want it to cover up the bottom of the screen, rather than push the HorizonalFieldManager and ad banner up.
Dont use setstatus for adding banner stuff instead you can use two horizontal managers at bottom of screen considering Display.getHeight().
I ve done similar kind of screen in my application here is the brief info regarding that.
1) parent Manager (either Vertical/Horizontal) say parentManager
2) Two Horozontal managers with appropriate height and Maximum width (override in sublayout of horizontal managers) and add both these two a verticalfield manager(bottommanager)
3) then here comes tricky part. To the parent Manger override sublayout and add these steps
vfm_screen = new VerticalFieldManager(ScrollView.NO_VERTICAL_SCROLL | HORIZONTAL_SCROLL
| NO_VERTICAL_SCROLL){
protected void sublayout(int maxWidth, int maxHeight) {
setPositionChild(parentManager, 0, 0);
layoutChild(parentManager, Display.getWidth(), Display.getHeight());
setPositionChild(bottommanager, 0, Display.getHeight()-114);
layoutChild(bottommanager, Display.getWidth(), 114);
setExtent(Display.getWidth(), Display.getHeight());
};
};
vfm_screen.add(parentManager);
vfm_screen.add(bottommanager);
add(vfm_screen);
Here 114 is hard sized and you can change it based on your requirement. and adding Button to that parent manger at center of screen.
Combine the ad-banner and the 3 justified fields with a VerticalFieldManager, then pass the combined manager to setStatus().

Multiple buttons with same width equal to widest button

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.

Resources