iOS--UI

Don't know if it helps your specific problem, however UITextAlignmentCenter does work if you use initWithStyle:UITableViewCellStyleDefault

loadView

loadView仅仅应该在开发者希望自行通过编码而不是Interface Builder定制view的时候被实现,而且不应该在其中调用[super loadView],你的loadView中应该有self.view = xxx这样的行为。

如果仅仅是想要在当前view上增加一些UIButton或是UILabel,应该在viewDidLoad里使用[self.view addSubView:xxx]去做,此时不要实现自己的loadView。下面是重写loadView的一个案例。

- ( void ) loadView {
    UIView *view = [ [ UIView alloc] initWithFrame:[ UIScreen
mainScreen] .applicationFrame] ;
    [ view setBackgroundColor:_color] ;
    self.view = view;
    [ view release] ;
}

你在控制器中实现了loadView方法,那么你可能会在应用运行的某个时候被内存管理控制调用。 如果设备内存不足的时候, view 控制器会收到didReceiveMemoryWarning的消息。 默认的实现是检查当前控制器的view是否在使用。 如果它的view不在当前正在使用的view hierarchy里面,且你的控制器实现了loadView方法,那么这个view将被release, loadView方法将被再次调用来创建一个新的view。

如何修改默认返回按钮的title

A视图-->B视图

现在想改变B视图返回A视图的返回按钮的title,只需在A视图中加上如下代码:

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
                                             initWithTitle:@"返回"
                                             style:UIBarButtonItemStylePlain
                                             target:self
                                             action:nil];

B视图不用做任何操作。

The backBarButtonItem exists specifically to change the appearance of the back button. If you need a custom action, you should consider using leftBarButtonItem instead.

下面就是使用leftBarButtonItem代替backBarButtonTtem的代码段,在B视图中viewDidLoad函数中实现。

在使用中发现,这样的实现其实是有问题的。返回按键只在B页面完全加载之后才出现,也就没有了从右向左滑入的效果。

    //返回按键
    UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction:)];
    UIImage *originalImage_normal = [UIImage imageNamed:@"nav_bar_back_button_normal.png"];
    UIImage *originalImage_selected = [UIImage imageNamed:@"nav_bar_back_button_selected.png"];
    UIImage *image_normal;
    UIImage *image_selected;
    
    // 拉伸图片
    if ([[UIImage class] respondsToSelector:@selector(resizableImageWithCapInsets:)]) {
        image_normal = [originalImage_normal resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12.5, 0, 7.5)];
        image_selected = [originalImage_selected resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12.5, 0, 7.5)];
    }
    else {
        image_normal = [originalImage_normal stretchableImageWithLeftCapWidth:12.5 topCapHeight:0];
        image_selected = [originalImage_selected stretchableImageWithLeftCapWidth:12.5 topCapHeight:0];
    }
    [backBarBtn setBackgroundImage:image_normal forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [backBarBtn setBackgroundImage:image_selected forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
    self.navigationItem.leftBarButtonItem = backBarBtn;
    self.navigationItem.leftBarButtonItem.target = self;
    [backBarBtn release];

获取iphone屏幕的宽度

    CGRect r = [ UIScreen mainScreen ].applicationFrame;
    r=0,20,320,460
    CGRect rx = [ UIScreen mainScreen ].bounds;
    r=0,0,320,480

在cell中添加subview图片

cell.inputView  或者 cell.contentView

// Configure the cell...

for (UIImageView *item in [cell.contentView subviews]) {
    if ([item isKindOfClass:[UIImageView class]]) {
	[item removeFromSuperview];
    }
}

模态视图 presentModalViewController

-(void)firstpressed
{
    //[[(ASSAppDelegate*)[UIApplication sharedApplication].delegate topStatusBar] setHidden:NO];
    [self.navigationController presentModalViewController:[[ASSRootViewController alloc] init] animated:YES];
}

关于覆盖层

下面是一段覆盖层的代码,特点是使用了keyWindow。

- (id)init
{
	CGRect frame = CGRectMake(0, 0, 320.0f, 400.0f);
	
	if((self = [super initWithFrame:frame]))
	{
		[super setBackgroundColor:[UIColor clearColor]];
        
		UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
        
        UIImageView *dimView = [[UIImageView alloc] initWithFrame:keyWindow.bounds];
        dimView.image = [self backgroundGradientImageWithSize:keyWindow.bounds.size];
        dimView.userInteractionEnabled = YES;
        
        [keyWindow addSubview:dimView];
        [self setCenter:CGPointMake(dimView.frame.size.width/2, dimView.frame.size.height/2)];
        [dimView addSubview:self];
        
        //...
    }
}

removeFromSuperview


[_overlay removeFromSuperview];
[_transition removeFromSuperview];

_overlay等在removeFromSupperview之后就会被释放掉(release)。

If the receiver’s superview is not nil, the superview releases the receiver. If you plan to reuse a view, be sure to retain it before calling this method and release it again later as appropriate.

IOS中view页面的堆栈操作


[self.navigationController popViewControllerAnimated:YES];

headView使用addSubview之后,不能够delease


UIView* headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];

headView.backgroundColor = [UIColor redColor];

UILabel* headLabel        = [[UILabel alloc] initWithFrame:CGRectMake(20,10, 200, 21)];
headLabel.backgroundColor = [UIColor greenColor];
headLabel.text            = @"Available control system";
headLabel.textColor       = [[UIColor alloc] initWithRed:128.0/255.0 green:133.0/255.0 blue:141.0/255.0 alpha:1.0];
//headLabel.center          = CGPointMake(headLabel.frame.size.width/2+18, headView.frame.size.height-headLabel.frame.size.height/2);
headLabel.shadowColor = [UIColor whiteColor];
headLabel.shadowOffset = CGSizeMake(0.0f, 0.5f);

[headView addSubview:headLabel];
[headView addSubview:self.scaningIndicatorView];

//[headView release];