开发者

iOS 5, Can't set NC Widget UIView height

开发者 https://www.devze.com 2023-03-24 19:33 出处:网络
I am creating a NC Widget and can\'t seem to adjust the height of the widget. Here is my code: -(UIView *)view {

I am creating a NC Widget and can't seem to adjust the height of the widget.

Here is my code:

-(UIView *)view {
if (_view == nil)
{
    CGRect frame = CGRectMake(2,0,316,191); // Added
    _view = [[[UIView alloc] initWithFrame:(frame)] autorelease]; //(2., 0., 316., 71.)]; <--ORIGINAL VALUE

    // Setting frame Height dont work... :/

    UIImage *bg = [[UIImage imageWithContentsOfFile:@"/开发者_JAVA百科System/Library/WeeAppPlugins/SMSWidget.bundle/Background.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:71];
    UIImageView *bgView = [[UIImageView alloc] initWithImage:bg];
    bgView.frame = CGRectMake(0, 0, 316, 191);
    [_view addSubview:bgView];
    [bgView release];

}


This is an example of how you can do that :

float myWidgetHeigth = 500 ; // The desired height
_view = [[UIView alloc] initWithFrame:CGRectMake(2, 0, 316, myWidgetHeigth)];

UIImage *bg = [[UIImage imageWithContentsOfFile:@"/System/Library/WeeAppPlugins/WorldClockNC.bundle/WeeAppBackground.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
UIImageView bgview = [[UIImageView alloc] initWithImage:bg];
bgview.frame = CGRectMake(0, 0, 316, myWidgetHeigth);
[_view addSubview:bgview];

If you are developing a plugin for the notification Center, refer to the BBWeeAppController-Protocol.h you will need also to implement this method : "- (float)viewHeight".

Also, I have seen from your code you are using theses methods "stretchableImageWithLeftCapWidth:5 topCapHeight:71", that are deprecated in IOS 5.0 --> https://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIImage/stretchableImageWithLeftCapWidth:topCapHeight: So, use the method "resizableImageWithCapInsets" ;-).

I'm not a pro on it, I'm learning ObjC, so if you have somes questions, let me know.

0

精彩评论

暂无评论...
验证码 换一张
取 消