Ios 在UIScrollview上显示图像的UIButton

Ios 在UIScrollview上显示图像的UIButton,ios,iphone,objective-c,ios6,uiscrollview,Ios,Iphone,Objective C,Ios6,Uiscrollview,要显示图像的ui按钮在ui滚动视图上完成。下面的代码显示了ui按钮,但当我滚动ui图像视图s时,它只显示在第一个图像视图上,我希望ui按钮done应该显示在ui视图中的所有图像视图上 - (void)viewDidLoad { self.view.backgroundColor = [UIColor blackColor]; UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,

要显示图像的
ui按钮
ui滚动视图
上完成。下面的代码显示了
ui按钮
,但当我滚动
ui图像视图
s时,它只显示在第一个图像视图上,我希望
ui按钮
done应该显示在
ui视图
中的所有图像视图上

 - (void)viewDidLoad

 {
 self.view.backgroundColor = [UIColor blackColor];
UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];

[myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];

myButton.frame = CGRectMake(0, 0, 60, 35);

[myButton.layer setMasksToBounds:YES];

[myButton.layer setCornerRadius:10.0f];

myButton.layer.borderWidth = 2;

myButton.layer.borderColor = [[UIColor whiteColor] CGColor];

[myButton setTitle:@"Done" forState:UIControlStateNormal];

myButton.backgroundColor = [UIColor blackColor];

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myButton];

[[self navigationItem] setRightBarButtonItem:button animated:YES];
imageScrollView.pagingEnabled = YES;
NSInteger numberOfViews = 61;
for (int i = 0; i < numberOfViews; i++) {
    CGFloat xOrigin = i * self.view.frame.size.width;

    NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);
    [imageScrollView addSubview:imageView];
    [imageScrollView addSubview:myButton];
    [imageView release];
   }
imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:imageScrollView];
[imageScrollView release];
 }
-(void)viewDidLoad
{
self.view.backgroundColor=[UIColor blackColor];
UIScrollView*imageScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
UIButton*myButton=[UIButton按钮类型:UIButtonTypeCustom];
[myButton addTarget:self action:@selector(dismissView:)for ControlEvents:UIControlEventTouchUpInside];
myButton.frame=CGRectMake(0,0,60,35);
[myButton.layer setMasksToBounds:是];
[myButton.layer setCornerRadius:10.0f];
myButton.layer.borderWidth=2;
myButton.layer.borderColor=[[UIColor whiteColor]CGColor];
[myButton设置标题:@“完成”状态:UIControlStateNormal];
myButton.backgroundColor=[UIColor blackColor];
UIBarButtonItem*按钮=[[UIBarButtonItem alloc]initWithCustomView:myButton];
[[self-navigationItem]setRightBarButtonItem:按钮动画:是];
imageScrollView.PaginEnabled=是;
NSInteger numberOfViews=61;
对于(int i=0;i

我应该如何对其进行编码,使其在滚动时在所有图像视图上显示
ui按钮。

在for循环中为myButton设置帧,类似于imageview帧

myButton.frame= CGRectMake(xOrigin, 0, self.myButton.frame.size.width, self.myButton.frame.size.height);

在for循环中添加
ui按钮
,即每次添加新的
ImageView
时都可以添加。 并为每个
imageView
-

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

    imageScrollView.pagingEnabled = YES;
    NSInteger numberOfViews = 61;

    for (int i = 0; i < numberOfViews; i++) 
    {
        CGFloat xOrigin = i * self.view.frame.size.width;
        UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [myButton addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
        myButton.frame = CGRectMake(xOrigin, 0, 60, 35);
        [myButton setTitle:@"Done" forState:UIControlStateNormal];
        myButton.backgroundColor = [UIColor blackColor];
        [myButton.layer setMasksToBounds:YES];

       [myButton.layer setCornerRadius:10.0f];
        myButton.layer.borderWidth = 2;
        myButton.layer.borderColor = [[UIColor whiteColor] CGColor];

        NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);
        [imageScrollView addSubview:imageView];
        [imageScrollView addSubview:myButton];
    }

    imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
    [self.view addSubview:imageScrollView];

}

没有必要这样做。这意味着您正在将该按钮设置在
导航栏的
rightBarButton
上,但在您的情况下,我认为您不想这样做。

将按钮代码添加到for循环中,以便它添加到每一行上……我这样添加了NSInteger numberOfViews=61;对于(inti=0;iUIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myButton]; [[self navigationItem] setRightBarButtonItem:button animated:YES];