Custom slideshow widget in Objective-c ui, objective-cui
The following is a custom carousel image class ImageLoop inherited from UIView. The class ImageLoop contains a UIScrollView and UIPageControl, which defines three attributes:
PageControll, position, currentPage can customize the pageControl style, you can also use position to control the playback direction, or set to start playing from an image whose subscript is currentPage.
The following is the ImageLoop interface file:
#import <UIKit/UIKit.h>typedef enum{Left,Right} Position;@interface ImageLoop : UIView@property (nonatomic,retain)UIPageControl *pageControll;@property (nonatomic,assign)Position position;@property (nonatomic,assign)NSInteger currentPage;- (instancetype)initWithFrame:(CGRect)frame imageArray:(NSMutableArray *)array position:(Position)position;@end
Initialize all controls in the initialization method, except pageControl, as well as scrollView, three uiimageviews, one timer
This demo carousel uses three uiimageviews to represent the displayed image, the left side of the displayed image, and the right side of the displayed image, by constantly setting the UIImage of three imageviews to achieve the carousel effect, when scrollView slides to the right, set the picture between the center and the left to the next image (pay attention to the boundary issue ), then let the scrollView slide to the middle, and then set the picture on the right to the next of the current image (also pay attention to the boundary issue), so that repeated playback can be achieved.
Because the control contains a timer, when the gesture slides, you need to stop the timer. After the image is switched successfully, a new timer is created to re-time the timer. Similarly, when the current image currentPage is set, you must stop the timer before restarting it. When you set the direction, the timer also stops and plays the video again based on the direction and timer.
The download link of the demo is as follows:
ImageLoop
Reprinted Please note: Author SmithJackyson