ios - 如何在 iOS 中创建 gmail 收件人格式?

标签 ios objective-c email gmail

我需要从收到的电子邮件数组中创建一个如下所示的 View ,该 View 也具有删除选项。

enter image description here

类似于 gmail 的邮件收件人的东西,除了我的 this 应该是 ScrollView 。我的主要问题是使用根据电子邮件长度延伸的删除按钮创建背景。我目前的方法是使用 3 张图片,一张作为开始,一张作为结尾,带有删除按钮,一张一般用于中间会拉伸(stretch)。有没有其他或更好的方法来做到这一点?

注意:需要iOS 5及以上的支持

最佳答案

给你,我创建了一个SuperLabel对你来说虽然它可能需要一些调整..但它肯定会帮助你..
SuperLabel.h

#import <UIKit/UIKit.h>

@interface SuperLabel : UIView
- (id)initWithFrame:(CGRect)frame andTitle:(NSString *)title;
@end
SuperLabel.m
#import "SuperLabel.h"

#define MAX_HEIGHT 25.0

@implementation SuperLabel

- (id)initWithFrame:(CGRect)frame andTitle:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

        //Design your label view
        self.backgroundColor=[UIColor colorWithRed:.8 green:.8 blue:.8 alpha:1.0];
        self.layer.borderColor=[[UIColor orangeColor] CGColor];
        self.layer.borderWidth=1.0;
        self.layer.cornerRadius=5.0;

        //Add a Label
        UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(5.0, 5.0, 100.0, MAX_HEIGHT)];
        label.font=[UIFont systemFontOfSize:12.0];
        label.textColor=[UIColor grayColor];
        label.text=title;
        [label sizeToFit];

        [self addSubview:label];

        //We will get resized frame after using sizeToFit after setting the text in the label.
        CGRect rect=label.frame;

        //Add a button
        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"x" forState:UIControlStateNormal];
        btn.titleLabel.font=[UIFont systemFontOfSize:12.0];
        btn.titleLabel.textColor=[UIColor grayColor];

        rect.origin.x=rect.origin.x+rect.size.width;
        rect.origin.y=0;
        rect.size=CGSizeMake(25.0, MAX_HEIGHT);

        [self addSubview:btn];

        [btn addTarget:self action:@selector(deleteMe:) forControlEvents:UIControlEventTouchDragInside];

        btn.frame=rect;


        //Change the whole frame of the label view
        frame.size.height=MAX_HEIGHT;
        frame.size.width=btn.frame.origin.x+btn.frame.size.width;

        self.frame=frame;


    }
    return self;
}


-(IBAction)deleteMe:(id)sender{
    [self removeFromSuperview];
}
@end

最后使用以下代码添加到您的 View 中。
    SuperLabel *label=[[SuperLabel alloc] initWithFrame:CGRectZero andTitle:@"myemail@gmail.com"];
    [self.view addSubview:label];

干杯..

关于ios - 如何在 iOS 中创建 gmail 收件人格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23469677/

相关文章:

ios - 如何将语音合成器静音

postgresql - bugzilla 无法连接到 postgres 服务器

ios - 使用自动布局时计算 UIScrollView 的 contentSize

ios - 使用 JavascriptCore 将 javascript 函数发送到 objective-C

objective-c - Core Data 持久存储保护

objective-c - 真实设备上的 NSDictionary 错误

objective-C:关于复制/保留 NSString 的简单问题

PHP 从 SQL 表邮寄数据

ruby-on-rails - 将 Roadie 3 与 Rails 4 结合使用

ios - 使用 tapGesture 自定义 UIView