Могу ли я добавить пользовательские элементы интерфейса в UIActionSheet? - PullRequest
0 голосов
/ 16 сентября 2011

Я успешно добавил кнопки в свой UIActionSheet.Мне было интересно, смогу ли я добавить другие элементы, отрегулировать непрозрачность и изменить направление всплывающей панели (по умолчанию входит снизу) с моим UIActionSheet?

Я относительно новичок в программировании на iOS, поэтому любая помощьбудет принята с благодарностью.

Ответы [ 3 ]

3 голосов
/ 16 сентября 2011

Если вы собираетесь настроить его до такой степени, вам лучше просто создать собственный настраиваемый вид наложения и добавить к нему все необходимые элементы управления. В частности, настройка направления анимации доставит больше хлопот, чем стоит.

Для получения дополнительной информации о пользовательских представлениях и иерархии представлений, а также полезного раздела об анимациях (см. Боковую панель), ознакомьтесь с View Programming Guide для iOS .

2 голосов
/ 16 сентября 2011

Написать реализацию!

//.h
#import <UIKit/UIKit.h>
@interface UIImageActionSheet : UIActionSheet {
    UIImage *titleImage;
}
-(id) initWithImage:(UIImage *)image 
              title:(NSString *)title 
           delegate:(id <UIActionSheetDelegate>)delegate 
  cancelButtonTitle:(NSString *)cancelButtonTitle 
   destructiveButtonTitle:(NSString *)destructiveButtonTitle 
  otherButtonTitles:(NSString *)otherButtonTitles;
@end


//.m file
#import "UIImageActionSheet.h"

@implementation UIImageActionSheet
-(id) initWithImage:(UIImage *)image 
              title:(NSString *)title
           delegate:(id <UIActionSheetDelegate>)delegate 
  cancelButtonTitle:(NSString *)cancelButtonTitle 
destructiveButtonTitle:(NSString *)destructiveButtonTitle 
  otherButtonTitles:(NSString *)otherButtonTitles{

    self = [super initWithTitle:title delegate:delegate 
              cancelButtonTitle:cancelButtonTitle 
         destructiveButtonTitle:destructiveButtonTitle 
              otherButtonTitles:otherButtonTitles,nil];

if (self) {
    titleImage=image;
    [titleImage retain];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:titleImage];
    imageView.frame = CGRectZero;         
        for (UIView *subView in self.subviews){
            if (![subView isKindOfClass:[UILabel class]]) {
                [self insertSubview:imageView aboveSubview:subView];
                break;
            }
        }

        [imageView release];
    }
    return self;
}


- (CGFloat) maxLabelYCoordinate {
// Determine maximum y-coordinate of labels
CGFloat maxY = 0;
for( UIView *view in self.subviews ){
    if([view isKindOfClass:[UILabel class]]) {
        CGRect viewFrame = [view frame];
        CGFloat lowerY = viewFrame.origin.y + viewFrame.size.height;
        if(lowerY > maxY)
            maxY = lowerY;
    }
}
return maxY;
}

-(void) layoutSubviews{
    [super layoutSubviews];
    CGRect frame = [self frame];
    CGFloat labelMaxY = [self maxLabelYCoordinate];

    for(UIView *view in self.subviews){
        if (![view isKindOfClass:[UILabel class]]) {    
            if([view isKindOfClass:[UIImageView class]]){
                CGRect viewFrame = CGRectMake((320 - titleImage.size.width)/2, labelMaxY + 10,
                                              titleImage.size.width, titleImage.size.height);
                [view setFrame:viewFrame];
            } 
            else if(![view isKindOfClass:[UIImageView class]]) {
                CGRect viewFrame = [view frame];
                viewFrame.origin.y += titleImage.size.height+10;
                [view setFrame:viewFrame];
            }
        }
    }

    frame.origin.y -= titleImage.size.height + 2.0;
    frame.size.height += titleImage.size.height + 2.0;
    [self setFrame:frame];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code.
}
*/

- (void)dealloc {
    [super dealloc];
    if (titleImage) {
        [titleImage release];
    }
}


@end
1 голос
/ 17 сентября 2011

Вы должны создать собственное наложение

...