uipagecontrol指示器(点)问题
大家好...
我想更改 uipagecontroller 指示器(点)颜色...为此,我正在执行以下步骤。
使用 2 个方法创建名为 PageControl 的新类
1.- (void) setCurrentPage:(NSInteger)page
2.- (void) setNumberOfPages:(NSInteger)pages
- (void) setCurrentPage:(NSInteger)page
{
NSLog(@"setCurrentPage");
[super setCurrentPage:page];
NSString* imgActive = [[NSBundle mainBundle] pathForResource:@"activeimage" ofType:@"png"];
NSString* imgInactive = [[NSBundle mainBundle] pathForResource:@"inactive" ofType:@"png"];
for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++)
{
UIImageView* subview= [self.subviews objectAtIndex:subviewIndex];
if (subviewIndex == page)
[subview setImage:[UIImage imageWithContentsOfFile:imgActive]];
else
[subview setImage:[UIImage imageWithContentsOfFile:imgInactive]];
subview.frame = CGRectMake(subview.frame.origin.x, subview.frame.origin.y, 10,10);
}
}
- (void) setNumberOfPages:(NSInteger)pages
{
NSLog(@"setNumberOfPages");
[super setNumberOfPages:pages];
NSString* img = [[NSBundle mainBundle] pathForResource:@"inactive" ofType:@"png"];
for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++)
{
UIImageView* subview= [self.subviews objectAtIndex:subviewIndex];
[subview setImage:[UIImage imageWithContentsOfFile:img]];
subview.frame = CGRectMake(subview.frame.origin.x, subview.frame.origin.y, 10,10);
}
}
已经我'我有一个带有页面控制和滚动视图的视图...这里我要做的是从笔尖中选择 uipagecontroller 并选择身份检查器并选择类名 PageControl(带有 2 种方法的新创建的类)它适用于在滑动时更改颜色图像但是,它不适用于单击页面控件移动到下一页...
我不知道我应该包含什么或我犯了什么错误...请帮助我做到这一点.. 。
谢谢...
Hai All...
I want to change the uipagecontroller indicator(dot) color...For that i'm doing the below steps.
Create new class named as PageControl with 2 methods
1.- (void) setCurrentPage:(NSInteger)page
2.- (void) setNumberOfPages:(NSInteger)pages
- (void) setCurrentPage:(NSInteger)page
{
NSLog(@"setCurrentPage");
[super setCurrentPage:page];
NSString* imgActive = [[NSBundle mainBundle] pathForResource:@"activeimage" ofType:@"png"];
NSString* imgInactive = [[NSBundle mainBundle] pathForResource:@"inactive" ofType:@"png"];
for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++)
{
UIImageView* subview= [self.subviews objectAtIndex:subviewIndex];
if (subviewIndex == page)
[subview setImage:[UIImage imageWithContentsOfFile:imgActive]];
else
[subview setImage:[UIImage imageWithContentsOfFile:imgInactive]];
subview.frame = CGRectMake(subview.frame.origin.x, subview.frame.origin.y, 10,10);
}
}
- (void) setNumberOfPages:(NSInteger)pages
{
NSLog(@"setNumberOfPages");
[super setNumberOfPages:pages];
NSString* img = [[NSBundle mainBundle] pathForResource:@"inactive" ofType:@"png"];
for (NSUInteger subviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++)
{
UIImageView* subview= [self.subviews objectAtIndex:subviewIndex];
[subview setImage:[UIImage imageWithContentsOfFile:img]];
subview.frame = CGRectMake(subview.frame.origin.x, subview.frame.origin.y, 10,10);
}
}
Already i'm having one view with pagecontrol and scrollview...Here what i'm doing is select the uipagecontroller from nib and choose identity inspector and select the class name PageControl(newly created class with 2 methods)it works for changing the color while swipe the images but,it didn't works for clicking the pagecontrol for moving to next page...
I don't know what shoud i want to include or what mistake i'm doing...please help me out to do this...
Thank You...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想在单击点时启用页面滚动,那么您需要首先将 xib 文件中的“值已更改”属性与您在代码中设置的操作相关联。
我已经在我的一个项目中实现了相同的功能,所以它肯定会起作用。
干杯
If you want to enable page scrolling on click of dot then you need to first of all associate the "value changed" property in your xib file to the action you set in your code.
I have implemented the same functionality in one of my projects so it will definitely work.
Cheers
你的上面的代码在 iOS 7 中崩溃了。我已经找到了这个问题的解决方案。我知道这不是办法,但可以肯定的是,直到 iOS 8 上市之前它都有效。
崩溃原因:
在 iOS 7 中
[self.subViews objectAtIndex: i]
返回UIView
而不是UIImageView
并且 setImage 不是 UIView 的属性,应用程序崩溃。我使用以下代码解决了我的问题。检查子视图是否为
UIView
(适用于 iOS7)或UIImageView
(适用于 iOS6 或更早版本)。如果它是 UIView,我将添加UIImageView
作为该视图上的子视图,瞧它的工作并且不会崩溃..!希望这也能解决 iOS7 的问题。如果有人找到最佳解决方案,请发表评论。 :)
快乐编码
Your above code is crashing in iOS 7.I have found a solution for this problem. I know it is not the way but Sure that it works till iOS 8 will be launched in the market.
Reason for Crash:
in iOS 7
[self.subViews objectAtIndex: i]
returnsUIView
Instead ofUIImageView
and setImage is not the property of UIView and the app crashes. I solve my problem using this following code.Check Whether the subview is
UIView
(for iOS7) orUIImageView
(for iOS6 or earlier). And If it is UIView I am going to addUIImageView
as subview on that view and voila its working and not crash..!!Hope this solve ur issue too for iOS7. and If Anypone find the optimal solution for that please comment. :)
Happy coding