gpt4 book ai didi

ios - iCarousel 中的按钮不起作用

转载 作者:行者123 更新时间:2023-11-29 00:18:21 25 4
gpt4 key购买 nike

我已经以编程方式设置了按钮,如下所示:-

-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view

{

UILabel *label = nil;
DoctorInfo *docInfo = self.allDoctorInfo[index];




//create new view if no view is available for recycling

if (view == nil)

{

//don’t do anything specific to the index within

//this `if (view == nil) {…}` statement because the view will be

//recycled and used with other index values later
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
CGFloat centerPoint = (view.frame.size.width / 2) - 25;

((UIImageView *)view).image = [UIImage imageNamed:@"card_shadowed.png"];
view.contentMode = UIViewContentModeCenter;
UIImageView *headImage = [[UIImageView alloc] initWithFrame:CGRectMake(centerPoint, -30, 50, 50)];
headImage.image = [UIImage imageNamed:@"face.png"];
[view addSubview:headImage];


//share button
UIButton *shareButton = [[UIButton alloc]initWithFrame:CGRectMake(170, -40, 20, 20)];
[shareButton setImage:[UIImage imageNamed:@"share_button.png"] forState:UIControlStateNormal];
[shareButton addTarget:self action:@selector(shareSelected:) forControlEvents:UIControlEventTouchUpInside];
[shareButton.superview setUserInteractionEnabled:YES];
shareButton.clipsToBounds = YES;
[view addSubview:shareButton];
[self.view bringSubviewToFront:shareButton];

return view;
}

并且在 viewdidload 中:-

 self.carousel.delegate = self;
self.carousel.dataSource = self;
self.carousel.type = iCarouselTypeTimeMachine;
self.carousel.userInteractionEnabled = YES;

我已经尝试了我在谷歌上搜索到的所有建议,但没有一个适用于我的情况。如何使 iCarousel 中的按钮可点击?

最佳答案

它的工作完美尝试这个代码

    func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {

var itemView = UIImageView()
itemView = UIImageView(frame: CGRect(x: 30, y: 0, width: carousel.frame.size.width - 60, height: 220 ))
itemView.image = UIImage(named: imagesArray[index])

itemView.contentMode = .scaleToFill
itemView.setCornerRadius(clipToBounds: true, radius: 10)
//itemView.setBorder(color: .red, width: 2)

let vwHeight = CGFloat(200)
let btnHeight = CGFloat(100)
let itemHeight = itemView.frame.size.height
let itemWidth = itemView.frame.size.width
let carouselX = CGFloat(30)

let customBtnView = UIView()
customBtnView.frame = CGRect(x: carouselX, y: itemHeight - vwHeight , width: itemWidth, height: vwHeight)

customBtnView.backgroundColor = UIColor.clear


let button = UIButton(type: .custom)
button.frame = CGRect(x: 0, y: 0, width: itemWidth, height: btnHeight)
button.backgroundColor = UIColor.clear
button.tag = carousel.currentItemIndex
button.addTarget(self, action: #selector(TutorialsVC.buttonNextAction), for: .touchUpInside)
customBtnView.addSubview(button)

carousel.addSubview(customBtnView)

return itemView

}

func buttonNextAction(sender: UIButton) {

print("Next==> \(sender.tag)")
switch sender.tag {
case 0:
//do action number 1
break
case 1:
//do action number 2
break
default:
break
}
}

关于ios - iCarousel 中的按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44733118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com