Screen size in pixel

CGRect screenBounds = [[UIScreen mainScreen] bounds];
That will give you the entire screen's resolution in points, so it would most typically be 320x480 for iPhones. Even though the iPhone4 has a much larger screen size iOS still gives back 320x480 instead of 640x960. This is mostly because of older applications breaking.

CGFloat screenScale = [[UIScreen mainScreen] scale];

This will give you the scale of the screen. For all iPhones and iPodTouches that do NOT have Retina Displays will return a 1.0f, while Retina Display devices will give a 2.0f.

Now if you want to get the pixel width & height of the iOS device screen you just need to do one simple thing.

CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);

By multiplying by the screen's scale you get the actual pixel resolution.

The usefulness of this code is that it will work in later products by Apple, such as if the iPad ever gets a Retina Display then using the scale will always get you the real pixel resolution.

A good read on the difference between points and pixels in iOS can be read here:http://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html#//apple_ref/doc/uid/TP40010156-CH14-SW7

See the UIScreen Reference:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html

if([[UIScreen mainScreen] respondsToSelector:NSSelectorFromString(@"scale")])
{
    if ([[UIScreen mainScreen] scale] < 1.1)
        NSLog(@"Standard Resolution Device");

    if ([[UIScreen mainScreen] scale] > 1.9)
        NSLog(@"High Resolution Device");
}
转帖: http://stackoverflow.com/questions/4779221/in-iphone-app-how-to-detect-the-screen-resolution-of-the-device




/** * @brief Displays characters in currently active layer. * @param Xpos X position (in pixel) * @param Ypos Y position (in pixel) * @param Text Pointer to string to display on LCD * @param Mode Display mode * This parameter can be one of the following values: * @arg CENTER_MODE * @arg RIGHT_MODE * @arg LEFT_MODE */ void UTIL_LCD_DisplayStringAt(uint32_t Xpos, uint32_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode) { uint32_t refcolumn = 1, i = 0; uint32_t size = 0, xsize = 0; uint8_t *ptr = Text; /* Get the text size */ while (*ptr++) size ++ ; /* Characters number per line */ xsize = (DrawProp->LcdXsize/DrawProp[DrawProp->LcdLayer].pFont->Width); switch (Mode) { case CENTER_MODE: { refcolumn = Xpos + ((xsize - size)* DrawProp[DrawProp->LcdLayer].pFont->Width) / 2; break; } case LEFT_MODE: { refcolumn = Xpos; break; } case RIGHT_MODE: { refcolumn = - Xpos + ((xsize - size)*DrawProp[DrawProp->LcdLayer].pFont->Width); break; } default: { refcolumn = Xpos; break; } } /* Check that the Start column is located in the screen */ if ((refcolumn < 1) || (refcolumn >= 0x8000)) { refcolumn = 1; } /* Send the string character by character on LCD */ while ((*Text != 0) & (((DrawProp->LcdXsize - (i*DrawProp[DrawProp->LcdLayer].pFont->Width)) & 0xFFFF) >= DrawProp[DrawProp->LcdLayer].pFont->Width)) { /* Display one character on LCD */ UTIL_LCD_DisplayChar(refcolumn, Ypos, *Text); /* Decrement the column position by 16 */ refcolumn += DrawProp[DrawProp->LcdLayer].pFont->Width; /* Point on the next character */ Text++; i++; } }
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值