Default UITableViewCellStyleSubtitle font size? - iphone

What is the default font size of textLabel and detailTextLabel?

You can always set any font to those labels in code so if you want some guaranteed fixed values you'd better do that as size values may vary depending on many factors (cell's style, sdk version, os version etc).
I've tested on simulator with 4.2 SDK version and got following results (no extra properties were set for cells):
UITableViewCellStyleSubtitle:
textLabel: Helvetica Bold, size: labelFontSize+1 (18 px)
detailsLabel: Helvetica, size: systemFontSize (14 px)
UITableViewCellStyleValue1:
textLabel: Helvetica Bold, size: labelFontSize (17 px)
detailsLabel: Helvetica Bold, size: systemFontSize+1 (15 px)
UITableViewCellStyleValue2:
textLabel: Helvetica Bold, size: smallSystemFontSize (12 px)
detailsLabel: Helvetica, size: labelFontSize (17 px)

The actual font size depends on the user's settings in Settings -> General -> TextSize. Normally, you shouldn't use a fixed font size, but should use something like:
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]
obviously depending on what you need. Anyway, if you create a UITableViewCell with style UITableViewCellStyleSubtitle, then the font of cell.text is the same object as
[UIFont preferredFontForTextStyle: UIFontTextStyleBody]
and the font of cell.detailTextLabel is the same object as
[UIFont preferredFontForTextStyle: UIFontTextStyleCaption1].
You get fonts from largest to smallest using the constants ending in "Body", "Subheadline", "Footnote", "Caption1", "Caption2" so you know what to use if you want slightly smaller or bigger text. "Headline" is same size as "Body" but bold.
It's probably best to just create a cell at runtime and get the fonts from it.

When I run this on the iPad 5.0 simulator:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
//set text to get font size > 0
NSLog(#"cellStyleValue2 text font: %#\n", cell.textLabel.font);
NSLog(#"cellStyleValue2 detail font: %#\n", cell.detailTextLabel.font);
I see:
cellStyleValue2 text font: font-family: "Helvetica"; font-weight: bold; font-style: normal; font-size: 12px
cellStyleValue2 detail font: font-family: "Helvetica"; font-weight: bold; font-style: normal; font-size: 15px
Since these parameters apparently vary, logging the font objects is good way to know without the guess work...

Related

Xcode: sizeWithFont:constrainedToSize:lineBreakMode: iPad issue with system text color?

I am using sizeWithFont:constrainedToSize:lineBreakMode: to work out the required height of my UITableViewcell's. The below code works fine in iPhone and iPad.
In IB (Storyboard) I have set the text color to "Dark Gray Color" (I am using separate storyboards for iPhone and iPad and I have set the colour in both.). iPhone behaves perfectly. iPad however is not using my Dark Gray, instead it apparently uses the default text color (Black) and I can't seem to change it. Is this perhaps a known bug or have I done something wrong?
Is there perhaps a way to add the text color programmatically in my sizeWithFont:constrainedToSize:lineBreakMode: or somewhere else?
Much appreciated.
if ([self.storyDescription description]) summary = [self.storyDescription description];
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
CGSize s = [summary sizeWithFont:[UIFont systemFontOfSize:15]
constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT) // - 40 For cell padding
lineBreakMode:UILineBreakModeWordWrap];
return s.height + 20; // Add padding
} else {
CGSize s = [summary sizeWithFont:[UIFont systemFontOfSize:18]
constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT) // - 40 For cell padding
lineBreakMode:UILineBreakModeWordWrap];
return s.height + 40; // Add padding
}
}
sizeWithFont:constrainedToSize:lineBreakMode: simply calculates the size of an NSString. Since NSString has no notion of colors, this method doesn't care about color either.
You should set the color in the Xcode Storyboard editor in the UILabel inspector. Alternatively, you can set a UITableViewCell's textLabel and detailTextLabel in the UITableView data source/delegate methods.

How to add views to UIWebVIew? like this image

I wonder how some apps do this great affect, i've trying to accomplish this but without much success.
the idea is to add views like textview or label to a webview or to scollview so that it appears with gray background and can be scrolled, the below image describes the intended goal :
I would be very much appreciated if you help me.
Use following code and just background color your UIView.Hope It will helps you.
[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
Use a pure HTML/javascript/CSS solution, not a native UIVIew laid on top of the UIWebView
CSS like this creates an initially invisible box, 400px wide, 120px from top, white background, bordered:
.floater
{
display: none;
position: absolute;
top: 120px;
left: 50%;
width: 400px;
margin-left: -200px;
z-index: 200;
background-color: #ffffff;
border-top: solid 2px #b0b0b0;
border-left: solid 2px #b0b0b0;
border-bottom: solid 2px black;
border-right: solid 2px black;
}
Use this class="floater" on your label, div, whatever.
You can then use the display style to hide/unhide it via javascript.
If you want your content to scroll within the webView, You have to add the view as a subview of the first subview of the webview.
The scrollview is the first subview of the webview
[[[webview subviews] objectAtIndex:0] addSubview:imageview];

Whats the font and color of UITableViewCell text?

I want to replicate the UITableViewCellStyleValue1 provided by apple, I just can't figure out the font and size of the text in the cells in the right. Specifically the font and color of numbers below is, 28 1 6843.
Use the default font with the label with the
size = [UIFont boldSystemFontOfSize:16];
and the color of the number you are looking for is
label.textColor = [UIColor colorWithRed:81.0/255.0 green:102.0/255.0 blue:145.0/255.0 alpha:1.0];
The area on the right of a UITableViewCell is called the detailTextLabel. You can just create a UITableViewCell with the style you want and read the UIFont and UIColor values from it.
UITableViewCell* cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: #"Example"] autorelease];
UIFont* rightFont = cell.detailTextLabel.font;
UIColor* rightColor = cell.detailTextLabel.textColor;
ITableViewCellStyleValue1
A style for a cell with a label on the left side of the cell with left-aligned and black text; on the right side is a label that has smaller blue text and is right-aligned. The Settings application uses cells in this style.

Change font name AND weight in UILabel (iPhone SDK)

Maybe I'm looking at the wrong place, however how do I set an UILabel's font and AND its weight?
Looking at the documentation, there seems to be only methods to create an UIFont with a given font name and size, like
[UIFont fontWithName:#"Helvetica" size:22])
OR create a bold font, with
[UIFont boldSystemFontOfSize:22]
How can I use these both together?
The documentation for fontWithName:size: states, "...name incorporates both the font family and the specific style information for the font."
So you probably want:
[UIFont fontWithName:#"Helvetica-Bold" size:22];
fontNamesForFamilyName: is handy for getting a list of available fonts for a given family.
For example:
NSArray* fontNames = [UIFont fontNamesForFamilyName:#"Helvetica"];
for( NSString* aFontName in fontNames ) {
NSLog( #"Font name: %#", aFontName );
}
...which outputs:
Font name: Helvetica-BoldOblique
Font name: Helvetica
Font name: Helvetica-Oblique
Font name: Helvetica-Bold

italic, bold and underlined font on iPhone

How do you set a font to be both bold and italic. There is a boldSystemFontOfSize and italicSystemFoneOfSize, but I can't see the way to set a font to be both italic and bold.
As a second question, is there a way to set an underline on a font, or do you simply draw a line under text.
You have to actually ask for the bold, italic version of a font. For example:
UIFont *myFont = [UIFont fontWithName:#"Helvetica-BoldOblique" size:[UIFont systemFontSize]];
To get a list of everything available on the iPhone, put this little snippet in your applicationDidFinishLaunching: delegate method and look at the log output:
for (NSString *family in [UIFont familyNames]) {
NSLog(#"%#", [UIFont fontNamesForFamilyName:family]);
}
Note: Some font names say "oblique" - this is the same as italic.
I can't see a built-in way of doing underlines - you may have to draw the line yourself.
I recently wrote a blog post about the restrictions of the UIFont API and how to solve it.
You can see it at http://eclipsesource.com/blogs/2012/07/26/uifont-from-a-css-definition/
With the code I provide there, you can get your desired system UIFont as easy as:
UIFont *myFont = [FontResolver fontWithDescription:#"font-family: sans-serif; font-weight: bold; font-style: italic;"];