如何使弹出登录窗口类似于istore在objective-C /可可触摸 [英] how can i make popup login window similar as on istore in objective-C/cocoa-touch

查看:189
本文介绍了如何使弹出登录窗口类似于istore在objective-C /可可触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有什么图书馆或可可触摸的特殊视图,有助于创建一个弹出窗口,当istore要求您的密码和名称?或透明视图与图像2文本字段和2个按钮?
我需要它,因为我想让我的登录屏幕类似。
感谢

解决方案

如果你想创建一个看起来类似的视图,你最好的打算是创建一个UIAlertView子类。您可以创建自己的子类并添加所需的元素。



在标题中创建如下所示的UIAlertView子类:

  @ interface LoginView:UIAlertView {
//实例vars
}

//方法和属性

@end



至于LoginView的实现,请注意以下事项...



为了调整UIAlertView的大小以适应您的内容(按钮,标签),您必须将消息文本设置为一些空行,例如您可以通过在UIAlertView子类上执行以下操作来添加5个空行:

  //这是UIAlertView的子类
@implementation LoginView

- (id)init
{
self = [super init];
if(self)
{
//根据需要添加更多的换行符
//控件(按钮,标签等)
[self setMessage:@\\\
\\\
\\\
\\\
\\\
];

CGRect frame = CGRectMake(10.0f,10.0f,200.0f,30.0f);
UILabel * label = [[UILabel alloc] initWithFrame:frame];
[label setBackgroundColor:[UIColor clearColor]];
[label setText:@Username:];
[self addSubview:label]
[label release];
}
return self;
}

^只需在任何其他UIView上添加按钮和标签。创建此视图的实例并调用 -show 方法显示视图,例如:

  #importLoginView.h

- (void)displayLogin
{
LoginView * loginView = [[[LoginView alloc] init] autorelease];
[loginView show];
}

为了使LoginView更加灵活,创建一个自定义初始化器,的类型 id )和选择器( SEL 类型)。当有人按下登录按钮时,使用目标和选择器执行实际登录。或者将登录代码放在LoginView本身中,并创建一个代理来通知调用者登录是否成功。



这种方法是hacky但结果看起来很不错:)



PS:请记住,当您创建这样的视图时, em> -setMessage:,因为它将重置视图的大小(框架)(或覆盖子类上的 setMessage:以防止调整大小)。如果您需要一些标签来撰写文字,请创建自己的标签并将其添加为子视图。


Hi is there any library or special view in cocoa touch which help to create a popup window like when the istore ask you for your password and name?or is it transparent view with image 2 textfields and 2 buttons? I need it because i want to make my login screen similar. thanks

解决方案

If you want to create a view that looks similar, your best bet is probably to create a UIAlertView subclass. You could create your own subclass and add the required elements.

Create a UIAlertView subclass like this in the header:

@interface LoginView : UIAlertView {
    // instance vars
}

// methods and properties 

@end 

As for the implementation of LoginView, please keep in mind the following ...

In order to resize the UIAlertView to fit your contents (buttons, labels), you'd have to set the message text to some amount of empty lines, e.g. you could add 5 empty lines by doing the following on your UIAlertView subclass:

// This is a subclass of UIAlertView 
@implementation LoginView

- (id)init 
{
    self = [super init];
    if (self) 
    {
        // add as many newlines as you need to fit
        // the controls (buttons, labels, etc...)
        [self setMessage: @"\n\n\n\n\n"]; 

        CGRect frame = CGRectMake(10.0f, 10.0f, 200.0f, 30.0f);
        UILabel *label = [[UILabel alloc] initWithFrame:frame];
        [label setBackgroundColor:[UIColor clearColor]];
        [label setText:@"Username:"];
        [self addSubview:label]
        [label release];
    }
    return self;
}

^ Just add buttons and labels like on any other UIView. Create an instance of this view and call the -show method to display the view, e.g.:

#import "LoginView.h"

- (void)displayLogin 
{
    LoginView *loginView = [[[LoginView alloc] init] autorelease];
    [loginView show];
}

To make the LoginView more flexible, create a custom initializer which accepts a target (of type id) and selector (of type SEL). When someone presses the login button, make it use the target and selector to perform the actual login. Or put the login code in the LoginView itself and create a delegate that informs the caller whether a login was successful.

This approach is kind of 'hacky' with the empty line stuff, but the result looks very nice :)

P.S.: remember that when you create a view like this, you shouldn't call -setMessage: on the instance, as it will reset the size (frame) of the view (or override setMessage: on the subclass to prevent resizing). If you need some label to write text on, create your own label and add it as a subview.

这篇关于如何使弹出登录窗口类似于istore在objective-C /可可触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆