Blackberry: Bold Font for LabelField text - blackberry

I am having the following code snippet in my application screen to show a label text in some bigger and good font. It looks good to me. But i also want to make this font to "bold" as well. Currently it doesn't show in boldfont as well. Could someone guide me how can i provide the label field text with the same font but also with bold ??? (or) Please tell me how can i make the label text with any other bigger size(24) font with bold?
LabelField subTitleLabel = new LabelField ("My App Sub Title", LabelField.FIELD_LEFT);
final FontFamily fontFamily[] = FontFamily.getFontFamilies();
final Font font10 = fontFamily[1].getFont(FontFamily.CBTF_FONT, 24);
subTitleLabel.setFont(font10);
subTitleLabel.setMargin(25, 0, 0, 10);
horEventFldManager.add(subTitleLabel);

This assumes that subTitleLabel is already set to the font that you want. It is just resetting it to a Bold version of that font.
subTitleLabel.setFont(subTitleLabel.getFont().derive(Font.BOLD));

Related

Label text clips at bottom when using CustomFont in iOS

I am using Custom Font in iOS application (Xamarin.Forms App). It is working fine but the text is clipped at the bottom of UILabel. It clearly cuts letter "g"
Custom Font: FuturaStd-Light.ttf
Actual Image In App:
Edited Image to ensure not height issue: Added Background color to Label to ensure it is not height issue.
I read here that to adjust ascender and descender property of Font. But still it doesn't help. Any help would be really appreciated.
Note: It is looking good if we remove custom font. The issue occurs only for the custom font that i am using.
you could try to use this:
NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle();
paragraphStyle.MinimumLineHeight = 24 + 1;//24 is your font size
NSMutableDictionary attributes = new NSMutableDictionary();//NSParagraphStyleAttributeName
attributes.SetValueForKey(paragraphStyle,new NSString("NSParagraphStyleAttributeName"));
label.AttributedText = new NSMutableAttributedString(label.Text,attributes);

what is the name of the font name used in iOS as system font

I was trying to set the font of UILabel manually. Previously, I use system font black of size 48.
so label.font = UIFont(name: "", size: CGFLoat(48))
what is the name it should be, to make the text of the label has the same look as system black 48.
Try this:
label.font = UIFont.systemFontOfSize(48)
Note that if this is not the right weight, you can instead (starting in iOS 8.2) call systemFontOfSize:weight:.

How to customize the button and label text size for each field separately in blackberry application?

I am new to BB application. I want customized the size for the button text and label text.
I am using this code
try {
FontFamily alphaSansFamily = FontFamily.forName("BBAlpha Serif");
Font appFont = alphaSansFamily.getFont(Font.PLAIN, 9, Ui.UNITS_pt);
setFont(appFont);
} catch (ClassNotFoundException e) {
}
but using this it will change size for what all the field we are using within the constructor.But I need different size for different field .Like Title will be big size and other label text button text will be small size.
I am guessing that you are calling that when you are creating the screen so the setFont() changes the font for the full screen.
You can call set font on the required button or label and it will change the font only for that field
e.g button.setFont(yourFont)
Are you calling setFont() explicitly on the Field you wish to change?
just in the above try block donot declere the statement setFont(appFont), this sets the font of the whole screen.
Insead set the font by specifying which label or button you want to set the font like
LabelField lf1 = new LabelField("Testing");
lf1.setFont(appFont);
Again
ObjectChoiceField ocf1 = new ObjectChoiceField("","","");
ocf1.setFont(appFont);

How to use Different font for LabelField like Arial,TimesNewRoman in BlackBerry

Hi friends I am using LabelFields to display text message in a screen i want different fonts each LabelField but when i am using api fonts of blackberry using
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font2 = fontFamily[0].getFont(FontFamily.SFF4_FONT,18);
is showing bold style how to use different font styles plz help me
try this
FontFamily alphaSerifFamily = FontFamily.forName("BBAlpha Serif");
Font appFont = alphaSerifFamily.getFont(Font.PLAIN,7,Ui.UNITS_pt);
LabelField lb = new LabelField("Test");
lb.setFont(appFont);

How to set a font to LabelField text in Blackberry?

I don't know how to apply font style to a text in a LabelField in Blackberry.
You can just use LabelField.setFont. If you don't do this explicitly on the label field, the field will use whatever font is used by its manager (and so on upward up the hierarchy).
There are a couple of ways to get a font. One is to derive one from an existing font (in this case I'm getting a bold version of the default font):
LabelField labelField = new LabelField("Hello World");
Font myFont = Font.getDefault().derive(Font.BOLD, 9, Ui.UNITS_pt);
labelField.setFont(myFont);
The other is to get a specific font family and derive a font from that (here getting a 12 pt italic font):
LabelField labelField = new LabelField("Hello World");
FontFamily fontFamily = FontFamily.forName("BBCasual");
Font myFont = fontFamily.derive(Font.ITALIC, 12, Ui.UNITS_pt);
labelField.setFont(myFont);
A couple of things to note: I used UNITS_pt (points) instead of UNITS_px (pixels). This is a good idea generally since BlackBerry devices vary quite a bit in screen size and resolution (DPI) and using points will give you a more consistent look across devices, instead of having your text look tiny on a Bold or 8900 (or huge on a Curve or Pearl).
Also in the second example, forName can throw a ClassCastException which you have to catch (it's a checked exception) but is never actually thrown according to the Javadocs, if you specify an unknown name, it'll fall back to another font family.
Here's a post which has a ResponseLabelField that extends LabelField and shows how to set the font:
http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=37988
Here's a quick code snippet for you:
LabelField displayLabel = new LabelField("Test", LabelField.FOCUSABLE)
{
protected void paintBackground(net.rim.device.api.ui.Graphics g)
{
g.clear();
g.getColor();
g.setColor(Color.CYAN);
g.fillRect(0, 0, Display.getWidth(), Display.getHeight());
g.setColor(Color.BLUE);
}
};
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font = fontFamily[1].getFont(FontFamily.CBTF_FONT, 8);
displayLabel.setFont(font);
Someone correct me if I'm wrong, but I believe different fonts are chosen by using a different index into the fontFamily array.
EDIT: And here's a test app you can use to switch between fonts: http://blackberry-digger.blogspot.com/2009/04/how-to-change-fonts-in-blackberry.html

Resources