首先确定是继承还是包含关系,最好是包含,然后你的View继承自UIView,把内部实现的接口都放在.m文件里,外面实在要用的才放在外面,暴露的接口不要放多,感觉几句话说不完。。
解决方案 »
- 把软件发布到ios deleverment 网站上,证书报错,,求解答
- 执行时报错,请高手指出一下。。我新手。。
- 判断近似圆。。。
- Objective-C语言,可以嵌入C语言么?
- 执行这段代码,程序会输出abc吗?
- ios7 模态时候 状态栏遮挡视图
- UIButton 的layer 在加入动画之后,点击事件就失效了
- Xcode6, _OBJC_CLASS_$_BaiduMobStat错误,求大神指导
- iOS项目移植
- ffmpeg Pcm 转AAC Specified sample format s16 is invalid or not supported
- 请问满屏显示怎么调整大小适配各种苹果版本
- 请教:陌陌, 微博, 微信之类的 server端架构是什么样的啊?
贴上代码:
#import <UIKit/UIKit.h>
@interface MyScrollview : UIView <
UIScrollViewDelegate,
UIScrollViewDelegate>
+(MyScrollview *)shareManager;
@property(nonatomic,strong) UIPageControl *newsPageControl;
-(void)setup:(NSArray *)picArray;
@end#import "MyScrollview.h"
@implementation MyScrollview
@synthesize newsPageControl;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.frame = CGRectMake(0.0, 64.0, 320.0, 175.0);
}
return self;
}
+(MyScrollview *)shareManager{
static MyScrollview *scroll = nil;
static dispatch_once_t onceTake;
dispatch_once(&onceTake, ^{
scroll = [[self alloc]init];
});
return scroll;
}
-(void)setup:(NSArray *)picArray{
UIScrollView *newScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 64.0, 320.0, 175.0)];
newScrollView.delegate = self;
newScrollView.pagingEnabled = YES;
for (int i = 0; i < picArray.count; i ++) {
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(i * 320.0, 0.0, 320.0, 175.0)];
img.image = [UIImage imageNamed:picArray[i]];
[newScrollView addSubview:img];
}
newsPageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(261, 210, 39, 37)];
newsPageControl.tintColor = [UIColor blackColor];
newsPageControl.currentPageIndicatorTintColor = [UIColor blueColor];
newsPageControl.currentPage = 0;
newsPageControl.numberOfPages = 3;
[self addSubview:newsPageControl];
}
@end
给个建议呗
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}这里面设置控件,
layoutSubviews设置frame?
在init方法中可初始化uiscrollview及uipagecontrol 并添加到当前控件中。在layoutsubview中根据picArray来修改uiscrollview的contentsize.可公开一个初始化法,我们更希望于这样这初始化一个控件
MyScrollview *mv =[[MyScrollview alloc] initWithPictures:XXX] ;
[self.view addSubview:mv];
#import <UIKit/UIKit.h>
@interface MyScrollview : UIView <
UIScrollViewDelegate
>
@property(nonatomic,strong) UIPageControl *newsPageControl;
@property(nonatomic,strong) NSArray *picArray;
-(void)setup;
@end#import "MyScrollview.h"
@implementation MyScrollview
@synthesize newsPageControl;
@synthesize picArray;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.frame = CGRectMake(0.0, 0.0, 320.0, 175.0);
[self setup];
}
return self;
}
-(void)setup{
UIScrollView *newScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 64.0, 320.0, 175.0)];
newScrollView.contentSize = CGSizeMake(320 * 3, 175);
newScrollView.showsVerticalScrollIndicator = NO;
newScrollView.delegate = self;
newScrollView.pagingEnabled = YES;
picArray = @[@"Phone29.png",@"Phone30.png",@"Phone31.png"];
for (int i = 0; i < picArray.count; i ++) {
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(i * 320.0, 0.0, 320.0, 175.0)];
img.image = [UIImage imageNamed:picArray[i]];
[newScrollView addSubview:img];
}
[self addSubview:newScrollView];
newsPageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(261, 210, 39, 37)];
newsPageControl.tintColor = [UIColor blackColor];
newsPageControl.currentPageIndicatorTintColor = [UIColor blueColor];
newsPageControl.currentPage = 0;
newsPageControl.numberOfPages = 3;
[self addSubview:newsPageControl];
}
-(void)scrollViewDidScroll:(UIScrollView*)scrollView{
[newsPageControl setCurrentPage:fabs(scrollView.contentOffset.x/self.frame.size.width)];
}
@end
mycrollview.picArray = @[@"Phone29.png",@"Phone30.png",@"Phone31.png"];
[self.view addSubview:mycrollview];
可是这样,运行起来是白板 啊
,实例化成功了的,我在初始化的时候吧图片扔进去就能显示出来,但是在外面调用就是不行,遍历picArray的时候image可以打印出来