我正在尝试开发一个库,它采用一组图像并返回一个滚动视图,其中每个图像并排。
但是,当我添加此滚动视图时,我将返回到我的主视图,它不会添加图像。图像是正确的。
我的想法是使用滚动视图与每个图像并排,并使用滚动条像幻灯片放映一样显示。首先,这个概念好吗?
其次,我不明白为什么在模拟器中运行应用程序时没有显示图像。
需要更多详细信息,请询问。
代码如下。我的头文件:
#import <UIKit/UIKit.h>
@interface HCIImageSlideShowView : UIScrollView
-(void) setImages:(NSArray*) imagesArray;
-(void) setBounds:(CGRect)bounds;
-(void) setCaptions:(NSArray*) imageCaptionsArray;
-(void) isEditable:(BOOL)edit;
-(void) setSlideTime:(int) milliSeconds;
-(void) startSlideShow;
- (id) initWithImages:(NSArray*)imagesArray captionsArray:(NSArray*) captionArray
bounds:(CGRect)bounds slideTime:(int)milliSeconds;
@end
我的实现文件:
#import "HCIImageSlideShowView.h"
#import "HCIResultListViewController.h"
@interface HCIImageSlideShowView ()
@property (strong,nonatomic) NSMutableArray *imagesArray;
@property BOOL editable;
@property (nonatomic) int slideTime;
@property (strong,nonatomic) NSMutableArray *imageCaptionsArray;
@property CGFloat width;
@end
@implementation HCIImageSlideShowView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (id) initWithImages:(NSArray*)imagesArray captionsArray:(NSArray*) captionArray
bounds:(CGRect)bounds slideTime:(int)milliSeconds
{
NSLog([NSString stringWithFormat:@"%f,%f", bounds.size.width , bounds.size.height]);
CGFloat width_t = bounds.size.width;
bounds.size.width = [imagesArray count] * bounds.size.width;
self = [[HCIImageSlideShowView alloc] initWithFrame:bounds];
_width = width_t;
[self setBackgroundColor:[[UIColor alloc] initWithRed:0.2 green:0.1 blue:0.3 alpha:0.4]];
if (self) {
[self setImages:imagesArray];
[self setSlideTime:milliSeconds];
[self setCaptions:captionArray];
[self defaultLoad];
}
self.scrollEnabled = YES;
return self;
}
-(void) defaultLoad
{
NSLog([NSString stringWithFormat:@"%f,%f,%f",_width,self.bounds.size.height,self.bounds.size.width]);
for (int i = 0; i < [_imagesArray count]; i++) {
CGRect imageBounds = CGRectMake(i * _width, self.bounds.size.height, _width, self.bounds.size.height);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageBounds];
[imageView setImage:[HCIResultListViewController resizeImage:_imagesArray[i] withWidth:_width withHeight:self.bounds.size.height]];
NSLog([NSString stringWithFormat:@"%f,%f",imageView.bounds.size.height,imageView.bounds.size.width]);
[self addSubview:imageView];
}
}
-(void) setBounds:(CGRect)bounds
{
self.bounds = bounds;
}
-(void) setImages:(NSArray *)imagesArray
{
_imagesArray = [[NSMutableArray alloc] initWithArray:imagesArray];
}
-(void) setSlideTime:(int)milliSeconds
{
_slideTime = milliSeconds;
}
-(void) startSlideShow
{
}
-(void) isEditable:(BOOL)edit
{
_editable = edit;
}
-(void) setCaptions:(NSArray *)imageCaptionsArray {
_imageCaptionsArray = [[NSMutableArray alloc] initWithArray:imageCaptionsArray];
}
@end