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.
精彩评论