有没有办法改变页面指示器点的颜色
我是 iPhone 编程新手,我正在尝试开发一个使用页面控制的应用程序。我的视图的背景颜色是白色,页面控制器默认的背景颜色也是白色,这使得页面控件在我的视图上不可见,因此我更改了页面控件的背景颜色以使其可见。现在,视图看起来已经修补且很糟糕。有没有办法只改变页面控制的点颜色?
提前致谢
I am newbie to iphone programming, I am trying to develop an app which uses page control. My view's background color is white and page controllers default one is also white, which makes page control invisible on my view so I have changed the back ground color of page control to make is visible. Now, the view appears patched and bad. Is there a way to change just the dots color for page control?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我们自定义了 UIPageControl 以使用自定义图像作为页面指示器,我在下面列出了该类的内部内容...
GrayPageControl.h
GrayPageControl.m
然后在视图控制器中我们就像普通的 UIPageControl 一样使用它
编辑:
在具有 GrayPageControl 的视图控制器中,我有一个链接到 GrayPageControl.ValueChanged 事件的 IBAction。
We customized the UIPageControl to use a custom image for the page indicator, I have listed the guts of the class below...
GrayPageControl.h
GrayPageControl.m
Then in the View Controller we just use it like a normal UIPageControl
Edit:
In the view controller that has the GrayPageControl I have an IBAction that is linked to the GrayPageControl.ValueChanged event.
应用程序在 iOS7 中崩溃。我有一个针对 iOS 7 的解决方案:
崩溃原因:
在 iOS 7 中
[self.subViews objectAtIndex: i]
返回UIView
而不是UIImageView
和setImage
不是UIView
的属性,应用程序崩溃。我使用以下代码解决了我的问题。检查子视图是否为
UIView
(适用于 iOS7)或UIImageView
(适用于 iOS6 或更早版本)。如果它是UIView
我将添加UIImageView
作为该视图上的子视图,瞧它的工作并且不会崩溃..!!希望这也能解决 iOS7 的问题。如果有人找到最佳解决方案,请发表评论。 :)
快乐编码
The application crashes in iOS7. I have a Solution for iOS 7:
Reason for Crash:
in iOS 7
[self.subViews objectAtIndex: i]
returnsUIView
Instead ofUIImageView
andsetImage
is not the property ofUIView
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 isUIView
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
JWD 的答案是要走的路。但是,如果您只想更改颜色,为什么不这样做:
此技术仅适用于 iOS6.0 及更高版本!
选择您的 UIPageControl 转到属性检查器。多田。
或者,您也可以尝试使用这两个属性:
这很简单。我又读了一遍问题,以确保我没有错。你真的只是想改变颜色不是吗?那么是的。
你仍然被那些法律点所困扰。使用 JWD 技术制作精美的点图。
JWD answer is the way to go. However, if all you want is to just change the color, why not do this:
This technique will only work on iOS6.0 and higher!
Select your UIPageControl go to attribute inspector. Tada.
Or alternatively you can play around with these 2 properties:
This is so simple. I read the question again to make sure I am not wrong. You really just want to change the color don't you? Then yes.
You're still stuck with that lawsy dots. Use JWD technique for the awesome dot pictures.
只需一行代码即可满足您的需求。该示例设置为黑色。
just one line of code fir your demand. The example set to black color.
DDPageControl 是一个很好的替代品。一探究竟!
您还可以在此处查看存档的博客文章。
DDPageControl is an excellent replacement. Check it out!
You can also view the archived blog post here.
您可以使用以下代码更改页面指示器色调颜色和当前页面指示器色调颜色:
You can change the page indicator tint color and the current page indicator tint color with the following code:
如果你只是想改变点的颜色或自定义它,你可以按照 JWD 的建议进行制作,但有另一种方式:
结果你会得到类似
还有宏:
if you just want to change color of dots or customize it you can make it as recommended by JWD, but in little bit another way:
As result you will get something like
Also macros:
最好、最简单的方法是在 AppDelegate.m 的 didFinishLaunchingWithOptions 方法中添加以下代码行
The best and most siple way to do this is to add the following lines of code in the didFinishLaunchingWithOptions method in the AppDelegate.m
您可能想看看此解决方案 在另一个 stackoverflow 问题中。
You might wanna have a look on this solution in another stackoverflow question.
这是使用自定义图像的相关答案(如果您很灵活并且可以使用图像而不是直接更改颜色)。
使用 UIPageControl 的图像自定义点在 UIPageControl 的索引 0 处
Here is a related answer for using a custom image (if you're flexible and can use an image rather than altering the colors directly).
Customize dot with image of UIPageControl at index 0 of UIPageControl