第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何更改UIPageControl的分頁點的顏色?

如何更改UIPageControl的分頁點的顏色?

iOS
慕村9548890 2019-12-07 15:31:56
我正在開發(fā)一個想要更改UIPageControl分頁點的顏色或圖像的應(yīng)用程序。我該如何更改?是否可以UIpageControl在上述情況下進行自定義?
查看完整描述

3 回答

?
互換的青春

TA貢獻(xiàn)1797條經(jīng)驗 獲得超6個贊

在iOS 6中,您可以設(shè)置的色調(diào)顏色UIPageControl:


有2個新屬性:


pageIndicatorTintColor

currentPageIndicatorTintColor

您還可以使用外觀API更改所有頁面指示器的顏色。


如果您以iOS 5為目標(biāo),請確保它不會崩潰:


if ([pageControl respondsToSelector:@selector(setPageIndicatorTintColor:)]) {

    pageControl.pageIndicatorTintColor = [UIColor whiteColor];

}


查看完整回答
反對 回復(fù) 2019-12-07
?
慕雪6442864

TA貢獻(xiàn)1812條經(jīng)驗 獲得超5個贊

如果有人想要它的ARC /現(xiàn)代版本(無需將屬性重新定義為ivar,無需取消分配,并且可以與Interface Builder一起使用):


#import <UIKit/UIKit.h>


@protocol PageControlDelegate;


@interface PageControl : UIView 


// Set these to control the PageControl.

@property (nonatomic) NSInteger currentPage;

@property (nonatomic) NSInteger numberOfPages;


// Customize these as well as the backgroundColor property.

@property (nonatomic, strong) UIColor *dotColorCurrentPage;

@property (nonatomic, strong) UIColor *dotColorOtherPage;


// Optional delegate for callbacks when user taps a page dot.

@property (nonatomic, weak) NSObject<PageControlDelegate> *delegate;


@end


@protocol PageControlDelegate<NSObject>

@optional

- (void)pageControlPageDidChange:(PageControl *)pageControl;

@end

PageControl.m:


#import "PageControl.h"



// Tweak these or make them dynamic.

#define kDotDiameter 7.0

#define kDotSpacer 7.0


@implementation PageControl


@synthesize dotColorCurrentPage;

@synthesize dotColorOtherPage;

@synthesize currentPage;

@synthesize numberOfPages;

@synthesize delegate;


- (void)setCurrentPage:(NSInteger)page

{

    currentPage = MIN(MAX(0, page), self.numberOfPages-1);

    [self setNeedsDisplay];

}


- (void)setNumberOfPages:(NSInteger)pages

{

    numberOfPages = MAX(0, pages);

    currentPage = MIN(MAX(0, self.currentPage), numberOfPages-1);

    [self setNeedsDisplay];

}


- (id)initWithFrame:(CGRect)frame 

{

    if (self = [super initWithFrame:frame]) 

    {

        // Default colors.

        self.backgroundColor = [UIColor clearColor];

        self.dotColorCurrentPage = [UIColor blackColor];

        self.dotColorOtherPage = [UIColor lightGrayColor];

    }

    return self;

}


-(id)initWithCoder:(NSCoder *)aDecoder

{

    if (self = [super initWithCoder:aDecoder])

    {

        self.dotColorCurrentPage = [UIColor blackColor];

        self.dotColorOtherPage = [UIColor lightGrayColor];

    }

    return self;

}


- (void)drawRect:(CGRect)rect 

{

    CGContextRef context = UIGraphicsGetCurrentContext();   

    CGContextSetAllowsAntialiasing(context, true);


    CGRect currentBounds = self.bounds;

    CGFloat dotsWidth = self.numberOfPages*kDotDiameter + MAX(0, self.numberOfPages-1)*kDotSpacer;

    CGFloat x = CGRectGetMidX(currentBounds)-dotsWidth/2;

    CGFloat y = CGRectGetMidY(currentBounds)-kDotDiameter/2;

    for (int i=0; i<self.numberOfPages; i++)

    {

        CGRect circleRect = CGRectMake(x, y, kDotDiameter, kDotDiameter);

        if (i == self.currentPage)

        {

            CGContextSetFillColorWithColor(context, self.dotColorCurrentPage.CGColor);

        }

        else

        {

            CGContextSetFillColorWithColor(context, self.dotColorOtherPage.CGColor);

        }

        CGContextFillEllipseInRect(context, circleRect);

        x += kDotDiameter + kDotSpacer;

    }

}



- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    if (!self.delegate) return;


    CGPoint touchPoint = [[[event touchesForView:self] anyObject] locationInView:self];


    CGFloat dotSpanX = self.numberOfPages*(kDotDiameter + kDotSpacer);

    CGFloat dotSpanY = kDotDiameter + kDotSpacer;


    CGRect currentBounds = self.bounds;

    CGFloat x = touchPoint.x + dotSpanX/2 - CGRectGetMidX(currentBounds);

    CGFloat y = touchPoint.y + dotSpanY/2 - CGRectGetMidY(currentBounds);


    if ((x<0) || (x>dotSpanX) || (y<0) || (y>dotSpanY)) return;


    self.currentPage = floor(x/(kDotDiameter+kDotSpacer));

    if ([self.delegate respondsToSelector:@selector(pageControlPageDidChange:)])

    {

        [self.delegate pageControlPageDidChange:self];

    }

}


@end


查看完整回答
反對 回復(fù) 2019-12-07
  • 3 回答
  • 0 關(guān)注
  • 943 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號