【问题标题】:iOS 5, Can't set NC Widget UIView heightiOS 5,无法设置 NC Widget UIView 高度
【发布时间】:2011-10-17 02:47:47
【问题描述】:

我正在创建一个NC Widget,但似乎无法调整小部件的高度。

这是我的代码:

-(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:@"/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];

}

【问题讨论】:

  • 这是哪里?如果它在 UIViewController 中,则覆盖 loadView。
  • 到底发生了什么?更具体地说明问题。只是发布一个吸气剂可以是任何事情..
  • 好的,我正在为 iPhone 进行调整,我需要获取视图以更改高度大小...我该怎么做?更改值不起作用...:/
  • 将 _view 更改为 view.. 简单来说,这段代码可以代表我们的任何东西 -(UIView *)view { // code } 的用途.. 它是您使用的函数还是只是在此处表示代码..请更具体。
  • 不能那样做,结果不好...但是 -(UIView *)view {//code} 是用于设置视图.. ( UI )。

标签: iphone objective-c uiview height


【解决方案1】:

这是你如何做到这一点的一个例子:

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];

如果您正在为通知中心开发插件,请参阅 BBWeeAppController-Protocol.h 您还需要实现此方法:“- (float)viewHeight”。

另外,我从您的代码中看到您正在使用这些方法“stretchableImageWithLeftCapWidth:5 topCapHeight:71”,这些方法在 IOS 5.0 中已弃用 --> https://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIImage/stretchableImageWithLeftCapWidth:topCapHeight:所以,请使用方法“resizableImageWithCapInsets”;-)。

我不是这方面的专家,我正在学习 ObjC,所以如果您有任何问题,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 2018-08-04
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 2016-11-18
    相关资源
    最近更新 更多