Iphone 这个新的UI组件是什么?如何编写它

Iphone 这个新的UI组件是什么?如何编写它,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我需要创建如下图所示的UI组件,而且我还需要知道 它叫什么?(灰色盒子) 如何向其中添加图像或任何其他UI组件 有没有创建这个的示例代码或教程 形象 我想那是哈得 回答您的问题: 1) 它叫什么 我会选择UIView——使用CALayer的corneradius设置和半透明背景色 2) 如何向其中添加图像或任何其他UI组件 [myview addSubview:someSubview] 3) 有没有创建这个的示例代码或教程 听起来你真的需要读一下这本书 MBProgressHud没有进

我需要创建如下图所示的UI组件,而且我还需要知道

  • 它叫什么?(灰色盒子)
  • 如何向其中添加图像或任何其他UI组件
  • 有没有创建这个的示例代码或教程
  • 形象


    我想那是哈得


    回答您的问题:

    1) 它叫什么

    • 我会选择
      UIView
      ——使用
      CALayer的
      corneradius
      设置和半透明背景色
    2) 如何向其中添加图像或任何其他UI组件

    • [myview addSubview:someSubview]
    3) 有没有创建这个的示例代码或教程

    • 听起来你真的需要读一下这本书

      • MBProgressHud没有进度条。我使用和创建了一个

        看起来是这样的:
        这样说:

        .h文件

        #import <UIKit/UIKit.h>
        #import "PDColoredProgressView.h"
        
        @interface SVProgressHudView : UIView<PDColoredProgressViewDelegate>{
            UIView*                 bgView;
            UILabel*                _titleLabel;
            PDColoredProgressView*  _progress;
            UILabel*                _percentLabel;
            UILabel*                _subtitleLabel;
            NSUInteger              _numOfSteps;
            NSUInteger              _currentStep;
            CGFloat                 _currentStepProgress;
            CGFloat                 _oneStepPart;
            CGFloat                 _extraStepPart;
            BOOL                    _removeFromSuperViewOnHide;
            BOOL                    _extraStep;
            UIButton*               _closeButton;
        }
        
        @property (nonatomic, assign)BOOL   removeFromSuperViewOnHide;
        
        +(SVProgressHudView *)hudAddedTo:(UIView *)view withTitle:(NSString*)title numberOfSteps:(NSUInteger)numberOfSteps extraStep:(BOOL)exrta;
        +(BOOL)isThereHudAddedToView:(UIView*)view;
        
        -(id)initWithFrame:(CGRect)frame title:(NSString*)title numberOfSteps:(NSUInteger)numberOfSteps extraStep:(BOOL)exrta;
        
        -(void)show:(BOOL)animated;
        -(void)hide:(BOOL)animated;
        -(void)setCurrentStepProgress:(CGFloat)currentProgress animated:(BOOL)animated;
        -(void)setCurrentStep:(NSUInteger)currentStep animated:(BOOL)animated;
        -(void)setExtraStepProgress:(CGFloat)progress animated:(BOOL)animated;
        
        -(void)setSuccessSubtitle:(NSString*)subtitle;
        
        -(void)setCloseButtonTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
        
        @end
        
        #导入
        #导入“PDColoredProgressView.h”
        @界面视图:UIView{
        UIView*bgView;
        UILabel*_标题标签;
        PDColoredProgressView*\u进度;
        UILabel*_%标签;
        UILabel*\u字幕标签;
        NSUInteger _numOfSteps;
        nsu整数_currentStep;
        CGFloat\u currentStepProgress;
        CGFloat(一步部分),;
        CGFloat extraStepPart;
        BOOL\u从Superview中移除隐藏;
        BOOL_extraStep;
        ui按钮*\u关闭按钮;
        }
        @属性(非原子,赋值)BOOL removeFromSuperViewOnHide;
        +(SVProgressHudView*)HUDDADEDTO:(UIView*)视图,标题为:(NSString*)标题数字步骤:(nsInteger)步骤外步骤的数字:(BOOL)exrta;
        +(BOOL)在此添加了视图:(UIView*)视图;
        -(id)initWithFrame:(CGRect)帧标题:(NSString*)标题numberOfSteps:(nsInteger)numberOfSteps extraStep:(BOOL)exrta;
        -(无效)显示:(BOOL)动画;
        -(void)隐藏:(BOOL)动画;
        -(void)setCurrentStepProgress:(CGFloat)currentProgress动画:(BOOL)动画;
        -(void)setCurrentStep:(nsInteger)currentStep已设置动画:(BOOL)已设置动画;
        -(void)setExtraStepProgress:(CGFloat)已设置进度动画:(BOOL)已设置动画;
        -(void)setSuccessSubtitle:(NSString*)子标题;
        -(void)setCloseButtonTarget:(id)目标操作:(SEL)controlEvents的操作:(uicontrol事件)controlEvents;
        @结束
        
        .m文件:

        #import "SVProgressHudView.h"
        #import <QuartzCore/QuartzCore.h>
        #import <Three20/Three20.h>
        #import "Three20UI/UIViewAdditions.h"
        #import "Globals.h"
        #import "SVGradientButton.h"
        
        #define kMinimumWidth           100
        #define kMinimumHeight          100
        
        #define kHorizontalMargin       20
        #define kVerticalMargin         20
        #define kLittleVerticalMargin   7
        #define kCornerRadius           10
        
        #define kOpacity                0.85
        
        static UIFont* regularSubtextFont;
        static UIFont* successSubtextFont;
        
        @interface SVProgressHudView(Private)
        
        -(void)done;
        
        @end
        
        @implementation SVProgressHudView
        
        @synthesize 
        removeFromSuperViewOnHide = _removeFromSuperViewOnHide;
        
        +(void)initialize{
            regularSubtextFont = [[UIFont systemFontOfSize:[UIFont systemFontSize]+3]retain];
            successSubtextFont = [[UIFont systemFontOfSize:[UIFont systemFontSize]+3]retain];
        }
        
        - (id)initWithFrame:(CGRect)frame{
            CGFloat minimumWidth = kMinimumWidth+kHorizontalMargin*2;
            CGFloat minimumHeight = kMinimumHeight + kVerticalMargin*2;
            //to ensure we can place it inside that frame
            if(frame.size.width>=minimumWidth && frame.size.height >=minimumHeight){
                self = [super initWithFrame:frame];
                if (self) {
                    CGFloat bgWidth = frame.size.width - kHorizontalMargin*2;
                    bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, bgWidth, kMinimumHeight)];
                    bgView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:kOpacity];
                    bgView.clipsToBounds = YES;
                    bgView.center = CGPointMake(self.width/2.0, self.height/2.0);
                    bgView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;
                    bgView.layer.cornerRadius = 10.0;
                    bgView.layer.masksToBounds = YES;
                    [self addSubview:bgView];
        
                    UIImage* closeImage = [UIImage imageNamed:@"xButton.png"];
                    _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
                    _closeButton.frame = CGRectMake(0, 0, closeImage.size.width*1.5, closeImage.size.height*1.5);
                    [_closeButton setBackgroundImage:closeImage forState:UIControlStateNormal];
                    [_closeButton addTarget:self action:@selector(closeFired) forControlEvents:UIControlEventTouchUpInside];
                    _closeButton.right = bgView.right +_closeButton.width/3;
                    [self addSubview:_closeButton];
        
                    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kHorizontalMargin, kVerticalMargin, bgWidth-kHorizontalMargin*2, 20)];
                    _titleLabel.textColor = [UIColor whiteColor];
                    _titleLabel.textAlignment = UITextAlignmentCenter;
                    _titleLabel.backgroundColor = [UIColor clearColor];
                    [bgView addSubview:_titleLabel];
        
                    _progress = [[PDColoredProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
                    _progress.delegate = self;
                    [_progress setBackgroundColor:[UIColor clearColor]];
                    [_progress setTintColor:[UIColor colorWithWhite:0.5 alpha:1.0]];//[Globals defaultTintColorForNavBar]];
                    [bgView addSubview:_progress];
                    [_progress sizeToFit];
                    _progress.top = _titleLabel.bottom+kVerticalMargin;
                    _progress.width = bgWidth-kHorizontalMargin*2-kCornerRadius*2;
                    _progress.left = kHorizontalMargin+kCornerRadius;
                    _progress.progress = 0.0;
        
                    _percentLabel = [[UILabel alloc]initWithFrame:CGRectMake(_progress.left, _progress.bottom+kLittleVerticalMargin, _progress.width/2, 20)];
                    _percentLabel.textColor = [UIColor whiteColor];
                    _percentLabel.textAlignment = UITextAlignmentLeft;
                    _percentLabel.backgroundColor = [UIColor clearColor];
                    _percentLabel.font = regularSubtextFont;
                    [bgView addSubview:_percentLabel];
        
                    _subtitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(_percentLabel.right, _percentLabel.top, _percentLabel.width, 20)];
                    _subtitleLabel.textColor = [UIColor whiteColor];
                    _subtitleLabel.textAlignment = UITextAlignmentRight;
                    _subtitleLabel.backgroundColor = [UIColor clearColor];
                    _subtitleLabel.font = regularSubtextFont;
                    [bgView addSubview:_subtitleLabel];
        
                    bgView.height = _subtitleLabel.bottom+kVerticalMargin;
                    bgView.center = self.center;
        
                    _closeButton.top = bgView.top - _closeButton.height/3;
        
                    _extraStep = NO;            
                }
            }
            return self;
        }
        
        -(id)initWithFrame:(CGRect)frame title:(NSString*)title numberOfSteps:(NSUInteger)numberOfSteps extraStep:(BOOL)exrta{
            self = [self initWithFrame:frame];
            if(self){
                _titleLabel.text = title;
                _numOfSteps = numberOfSteps;
                _extraStep = exrta;
                if(_extraStep){
                    CGFloat stepPart = 1.0/numberOfSteps;
                    _extraStepPart = stepPart/10;
                    _oneStepPart = (1.0-_extraStepPart)/numberOfSteps;
                }else{
                    _oneStepPart = 1.0/numberOfSteps;
                }
                [self setCurrentStep:0 animated:NO];
            }
            return self;
        }
        
        -(void)dealloc{
            TT_RELEASE_SAFELY(_titleLabel);
            TT_RELEASE_SAFELY(_subtitleLabel);
            TT_RELEASE_SAFELY(_percentLabel);
            TT_RELEASE_SAFELY(_progress);
            TT_RELEASE_SAFELY(bgView);
            [super dealloc];
        }
        
        #pragma mark - Showing and Hiding
        
        - (void)show:(BOOL)animated {
            self.alpha = 0.0;
            // Fade in
            if (animated) {
                [UIView animateWithDuration:0.3 
                                 animations:^{
                                     self.alpha = 1.0;
                                 }];
            }else {
                self.alpha = 1.0;
            }
        }
        
        - (void)hide:(BOOL)animated {
            if (animated) {
                [UIView animateWithDuration:0.3
                                 animations:^{
                                     self.alpha = 0.2;
                                 } 
                                 completion:^(BOOL finished) {
                                     [self done];
                                 }];
            }
            else {
                [self done];
            }
        }
        
        #pragma mark - Private Methods
        
        - (void)done {
            self.alpha = 0.0;
            if (_removeFromSuperViewOnHide) {
                [self removeFromSuperview];
            }
        }
        
        #pragma mark - Public Methods
        
        + (BOOL)isThereHudAddedToView:(UIView*)view{
            for (UIView *v in [view subviews]) {
                if ([v isKindOfClass:[SVProgressHudView class]]) {
                    return YES;
                }
            }
            return NO;
        }
        
        + (SVProgressHudView *)hudAddedTo:(UIView *)view withTitle:(NSString*)title numberOfSteps:(NSUInteger)numberOfSteps extraStep:(BOOL)exrta{
            SVProgressHudView *hud = [[SVProgressHudView alloc] initWithFrame:view.bounds title:title numberOfSteps:numberOfSteps extraStep:exrta];
            hud.alpha = 0.0;
            [view addSubview:hud];
            return [hud autorelease];
        }
        
        -(void)setCurrentStepProgress:(CGFloat)currentStepProgress animated:(BOOL)animated{
            if(currentStepProgress < 0.0){
                currentStepProgress = 0.0;
            }
            if(currentStepProgress > 1.0){
                currentStepProgress = 1.0;
            }
            CGFloat currentProgress = _oneStepPart*_currentStep;
            currentProgress += _oneStepPart*currentStepProgress;
            [_progress setProgress:currentProgress animated:animated];
        }
        
        -(void)setCurrentStep:(NSUInteger)currentStep animated:(BOOL)animated{
            if(currentStep > _numOfSteps){
                currentStep = _numOfSteps;
            }
            _currentStep = currentStep;
            _subtitleLabel.text = [NSString stringWithFormat:@"%d/%d",currentStep+1,_numOfSteps];
            _subtitleLabel.font = regularSubtextFont;
            [self setCurrentStepProgress:0.0 animated:animated];
        }
        
        -(void)setExtraStepProgress:(CGFloat)progress animated:(BOOL)animated{
            if(progress < 0.0){
                progress = 0.0;
            }
            if(progress > 1.0){
                progress = 1.0;
            }
            if(progress == 1.0){
                //hide the close button
                _closeButton.hidden = YES;
            }
            CGFloat currentProgress = _oneStepPart*_numOfSteps;
            currentProgress += _extraStepPart*progress;
            [_progress setProgress:currentProgress animated:animated];
        }
        
        -(void)progressUpdated:(PDColoredProgressView *)progressView toValue:(CGFloat)value{
            _percentLabel.text = [NSString stringWithFormat:@"%d%%",(int)(value*100)];
        }
        
        -(void)setSuccessSubtitle:(NSString *)subtitle{
            [_progress setProgress:1.0 animated:YES];
            _subtitleLabel.text = subtitle;
            _subtitleLabel.font = successSubtextFont;
        }
        
        -(void)closeFired{
            [_progress cancelAnimations];
        }
        
        -(void)setCloseButtonTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents{
            [_closeButton addTarget:target action:action forControlEvents:controlEvents];
        }
        
        @end
        
        #导入“SVProgressHudView.h”
        #进口
        #进口
        #导入“Three20UI/UIViewAdditions.h”
        #导入“Globals.h”
        #导入“SVGradientButton.h”
        #定义最小宽度100
        #定义最小高度100
        #定义kHorizontalMargin 20
        #定义kVerticalMargin 20
        #定义kLittleVerticalMargin 7
        #定义kCornerRadius 10
        #定义kOpacity 0.85
        静态UIFont*常规SubtextFont;
        静态UIFont*successSubtextFont;
        @界面视图(专用)
        -(无效)完成;
        @结束
        @实现视图
        @综合
        removeFromSuperViewOnHide=\u removeFromSuperViewOnHide;
        +(无效)初始化{
        regularSubtextFont=[[UIFont systemFontOfSize:[UIFont systemFontSize]+3]保留];
        successSubtextFont=[[UIFont systemFontOfSize:[UIFont systemFontSize]+3]保留];
        }
        -(id)initWithFrame:(CGRect)帧{
        CGFloat最小宽度=KminimimumWidth+kHorizontalMargin*2;
        CGFloat minimumHeight=kMinimumHeight+kVerticalMargin*2;
        //为了确保我们能把它放在那个框架里
        if(frame.size.width>=最小宽度和&frame.size.height>=最小高度){
        self=[super initWithFrame:frame];
        如果(自我){
        CGFloat bgWidth=frame.size.width-霍利佐塔尔马金*2;
        bgView=[[UIView alloc]initWithFrame:CGRectMake(0,0,bgWidth,kMinimumHeight)];
        bgView.backgroundColor=[[UIColor blackColor]colorWithAlphaComponent:kOpacity];
        bgView.clipstobunds=是;
        bgView.center=CGPointMake(self.width/2.0,self.height/2.0);
        bgView.autoresizingMask=UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | uiviewautoresizingflexibleleleftmargin | UIViewAutoresizingFlexibleBottomMargin;
        bgView.layer.cornerRadius=10.0;
        bgView.layer.masksToBounds=是;
        [自添加子视图:bgView];
        UIImage*closeImage=[UIImage ImageName:@“xButton.png”];
        _closeButton=[UIButton按钮类型:UIButtonTypeCustom];
        _closeButton.frame=CGRectMake(0,0,closeImage.size.width*1.5,closeImage.size.height*1.5);
        [\u closeButton setBackgroundImage:closeImage for状态:UIControlStateNormal];
        [_closeButtonaddTarget:self action:@selector(closeFired)for controlEvents:UIControlEventTouchUpInside];
        _closeButton.right=bgView.right+_closeButton.width/3;
        [自添加子视图:_closeButton];
        _titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(霍利佐塔尔马金,克沃尔蒂卡马金,bgWidth霍利佐塔尔马金*2,20)];
        _titleLabel.textColor=[UIColor whiteColor];
        _titleLabel.textAlignment=UITextAlignmentCenter;
        _titleLabel.backgroundColor=[UIColor clearColor];
        [bgView addSubview:_titleLabel];
        _进度=[[PDColoredProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
        _progress.delegate=self;
        [_progresssetbackgroundcolor:[UIColor clearColor]];
        [_progresssetTintColor:[UIColor-WithWhite:0.5 alpha:1.0]];//[Globals defaultTintColorForNavBar]];
        [bgView addSubview:_进度];
        [_进度大小匹配];
        _progress.top=_titleLabel.bottom+kVerticalMargin;
        _progress.width=bgWidth kHorizontalMargin*2-kCornerRadius*2;
        _progress.left=霍利佐塔尔马金+科内拉迪乌斯;
        _progress.progress=0.0;
        _percentLabel=[[UILabel alloc]初始化