Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe997a6

Browse files
肖睿肖睿
authored andcommitted
新增“设置图片内容模式”的接口
1 parent c788ed2 commit fe997a6

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

XRCarouselView/XRCarouselView.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ typedef enum {
2828

2929

3030

31-
31+
/**
32+
* 代理
33+
*/
3234
@protocol XRCarouselViewDelegate <NSObject>
3335

3436
/**
@@ -66,11 +68,17 @@ typedef enum {
6668

6769

6870
/**
69-
* 设置图片切换的模式,默认为ChangeModeDefault
71+
* 设置图片的切换模式,默认为ChangeModeDefault
7072
*/
7173
@property (nonatomic, assign) ChangeMode changeMode;
7274

7375

76+
/**
77+
* 设置图片的内容模式,默认为UIViewContentModeScaleToFill
78+
*/
79+
@property (nonatomic, assign) UIViewContentMode contentMode;
80+
81+
7482
/**
7583
* 设置分页控件位置,默认为PositionBottomCenter
7684
* 只有一张图片时,pageControl隐藏
@@ -118,7 +126,7 @@ typedef enum {
118126
/**
119127
* 构造方法
120128
*
121-
* @param imageArray 图片数组
129+
* @param imageArray 图片数组
122130
* @param describeArray 图片描述数组
123131
*
124132
*/
@@ -158,7 +166,7 @@ typedef enum {
158166
* 设置分页控件指示器的颜色
159167
* 不设置则为系统默认
160168
*
161-
* @param color 其他页码的颜色
169+
* @param color 其他页码的颜色
162170
* @param currentColor 当前页码的颜色
163171
*/
164172
- (void)setPageColor:(UIColor *)color andCurrentPageColor:(UIColor *)currentColor;

XRCarouselView/XRCarouselView.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ - (UIScrollView *)scrollView {
7777
//添加手势监听图片的点击
7878
[_scrollView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClick)]];
7979
_currImageView = [[UIImageView alloc] init];
80+
_currImageView.clipsToBounds = YES;
8081
[_scrollView addSubview:_currImageView];
8182
_otherImageView = [[UIImageView alloc] init];
83+
_otherImageView.clipsToBounds = YES;
8284
[_scrollView addSubview:_otherImageView];
8385
}
8486
return _scrollView;
@@ -137,6 +139,13 @@ - (void)setFrame:(CGRect)frame {
137139
[self addSubview:self.pageControl];
138140
}
139141

142+
#pragma mark 设置图片的内容模式
143+
- (void)setContentMode:(UIViewContentMode)contentMode {
144+
_contentMode = contentMode;
145+
_currImageView.contentMode = contentMode;
146+
_otherImageView.contentMode = contentMode;
147+
}
148+
140149
#pragma mark 设置图片数组
141150
- (void)setImageArray:(NSArray *)imageArray{
142151
if (!imageArray.count) return;

XRCarouselViewDemo/XRCarouselViewDemo/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ - (void)viewDidLoad {
3939
//设置frame
4040
self.carouselView.frame = CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 180);
4141

42-
42+
4343
//用代理处理图片点击
4444
self.carouselView.delegate = self;
4545

XRCarouselViewDemo/XRCarouselViewDemo/XRCarouselView/XRCarouselView.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ typedef enum {
2828

2929

3030

31-
31+
/**
32+
* 代理
33+
*/
3234
@protocol XRCarouselViewDelegate <NSObject>
3335

3436
/**
@@ -66,11 +68,17 @@ typedef enum {
6668

6769

6870
/**
69-
* 设置图片切换的模式,默认为ChangeModeDefault
71+
* 设置图片的切换模式,默认为ChangeModeDefault
7072
*/
7173
@property (nonatomic, assign) ChangeMode changeMode;
7274

7375

76+
/**
77+
* 设置图片的内容模式,默认为UIViewContentModeScaleToFill
78+
*/
79+
@property (nonatomic, assign) UIViewContentMode contentMode;
80+
81+
7482
/**
7583
* 设置分页控件位置,默认为PositionBottomCenter
7684
* 只有一张图片时,pageControl隐藏
@@ -118,7 +126,7 @@ typedef enum {
118126
/**
119127
* 构造方法
120128
*
121-
* @param imageArray 图片数组
129+
* @param imageArray 图片数组
122130
* @param describeArray 图片描述数组
123131
*
124132
*/
@@ -158,7 +166,7 @@ typedef enum {
158166
* 设置分页控件指示器的颜色
159167
* 不设置则为系统默认
160168
*
161-
* @param color 其他页码的颜色
169+
* @param color 其他页码的颜色
162170
* @param currentColor 当前页码的颜色
163171
*/
164172
- (void)setPageColor:(UIColor *)color andCurrentPageColor:(UIColor *)currentColor;

XRCarouselViewDemo/XRCarouselViewDemo/XRCarouselView/XRCarouselView.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ - (UIScrollView *)scrollView {
7777
//添加手势监听图片的点击
7878
[_scrollView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClick)]];
7979
_currImageView = [[UIImageView alloc] init];
80+
_currImageView.clipsToBounds = YES;
8081
[_scrollView addSubview:_currImageView];
8182
_otherImageView = [[UIImageView alloc] init];
83+
_otherImageView.clipsToBounds = YES;
8284
[_scrollView addSubview:_otherImageView];
8385
}
8486
return _scrollView;
@@ -137,6 +139,13 @@ - (void)setFrame:(CGRect)frame {
137139
[self addSubview:self.pageControl];
138140
}
139141

142+
#pragma mark 设置图片的内容模式
143+
- (void)setContentMode:(UIViewContentMode)contentMode {
144+
_contentMode = contentMode;
145+
_currImageView.contentMode = contentMode;
146+
_otherImageView.contentMode = contentMode;
147+
}
148+
140149
#pragma mark 设置图片数组
141150
- (void)setImageArray:(NSArray *)imageArray{
142151
if (!imageArray.count) return;

0 commit comments

Comments
 (0)