pagecontrol indicator custom image instead of Default - iphone

How can i change the color of pagination dots of UIPageControl?
In this link the sample code is given.But it shows 3 errors for me...
1'st ERROR:
Line:CGRect currentBounds = self.bounds;
Error:requst for member 'bounds' in something not a structure or union
Method:-(void)drawRect:
2nd Err: same error with same line in touchesBegan method.
3rd Err:#protocol PageControlDelegate
#optional
(void)pageControlPageDidChange:(PageControl *)pageControl;
#end
Error:Expected ')' before 'PageControl' .These are the three errors occurs for me...Please help me out to solve this..
I want to change the pagecontrol indicator(dot) color...
Thanks & Regards,
Renuga

first error is probably due to the fact that self does not refer to a view (a view controller maybe)
Second error is because PageControl is not yet defined by the time the parser come to your protocol definition.
Typical Class with delegate
#protocol MyProtocol;
#interface myClassWithDelegate
{
id<MyProtocol> _delagate;
}
#end
#protocol MyProtocol
-(void)MyClass:(MyClassWithDelegate*)c says(NSString*)message;
#end

I'm the one who wrote the sample code you are using.
I see that VdesmedT has already helped you on the syntax issues you were having. So +1 for that!
As for customizing the dots: The class as provided does not support custom images for the dots. It just draws circles using Core Graphics. The color of the circles is configured using the properties dotColorCurrentPage and dotColorOtherPage.
The default colors are grey dots with a black dot for the current page (because that is what I needed when I wrote it).
Let's say you want a red dot instead of a black dot for the current page and green dots for the other pages. When you create your PageControl instance you simply assign the properties like this:
pageControl.dotColorCurrentPage = [UIColor redColor];
pageControl.dotColorOtherPage = [UIColor greenColor];
... assuming your instance variable is called pageControl. Or use any of the other convenience/initialization methods for creating a UIColor that you like.
Hope this helps.

Related

Buttons obstructed due to UIView created due to custom table view style code (Xcode8)

I use the following code to change the background colour and border radius of a UITableView:
let containerView:UIView = UIView(frame:self.gamesTableView.frame)
gamesTableView.layer.cornerRadius = 5
gamesTableView.layer.masksToBounds = true
gamesTableView.backgroundColor = UIColor(red:1, green:1, blue:1, alpha:0.40)
self.view.addSubview(containerView)
containerView.addSubview(gamesTableView)
This worked fine in xcode 7 and produced the result I expected. However in Xcode 8 this code seems to cause the buttons on the screen not to work, using the debug view hierarchy tool I discovered that with this code there is an extra UIView created that seems to obstruct the buttons. Removing the code in question does solve the problem but it also takes away the extra traits I gave the table view. I would like to know whether there is an alternative method to achieve the same result. I have included images of the view hierarchy with and with out the code.
The buttons in question are: "Start new game" and "Settings"
Side view without styling code:
Side view with sling code, notice the highlighted layer in front:
The fix for this seems to be as simple as putting the code in the question above in viewDidLayoutSubviews
Like this:
override func viewDidLayoutSubviews(){
let containerView:UIView = UIView(frame:self.gamesTableView.frame)
gamesTableView.layer.cornerRadius = 5
gamesTableView.layer.masksToBounds = true
gamesTableView.backgroundColor = UIColor(red:1, green:1, blue:1, alpha:0.40)
self.view.addSubview(containerView)
containerView.addSubview(gamesTableView)
}

On scrolling tableView in subclass of UIView it appends white ugly marks in View?

I have made a custom combo files that is using in my project.Those files are here
UICombo.h and UICombo.m.
All is working fine except it add white mark over my super view on which it is added while scrolling.
I am not able to understand why it is happening.Any solution will be appreciated.
Using combo code here ...
UICombo *mwCombo;
mwCombo=[[UICombo alloc] initWithFrame:CGRectMake(10, 48, 177, 30) andItems:nil];
[mwCombo setAutoresizingMask:(UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleRightMargin )];
[self.view addSubview:mwCombo];
My screen shots are give below.
Thanks!
set tableview z-position to -100 that is less than 0.And it is working as I have implemented in your example codes.Try adding following line before adding table view to self in init method in UICombo.m file.
[_tableView.layer setZPosition:-100];
I think you need to use the clipsoBounds property of your UICombo or on some of the views that it uses internally to draw itself. If you have structured this class nicely it will manage any other views that get created when it expands and on one of those views you should set clipsToBounds to YES, perhaps on the table-view itself.

I'm struggling to compare a UIcolor that I have made

I've built a set of custom colours to use in my app, such as lime
mylimeColor = [UIColor colorWithRed:0.502 green:1.000 blue:0.000 alpha:1.000];
Setting something to this colour works fine, but I'm struggling later in my app when I want to change something depending on which of my custom colours a view has.
I was using the following with no issue:
if (bgColor == [UIColor redColor]) {
// do something
}
but this breaks as soon as I start to use my own colours.
if (bgColor == myredColor) {
// do something
}
I can check the background colour in NSLog and it looks exactly as I would expect.
Is there another way for me to find out what the background of something (UIView, UITextFeild, etc) is? I have looked online but only seem to be finding help setting my custom colours, which hasn't been an issue for me.
My next step is going to be to set an integer to a specific number with each colour and check that instead, but it seems that comparing the colour itself would be a better way of doing this.
Thanks for your help!!
UIColor is a class. Use the isEqual: to compare the colors.

Why cant I display the layer property value of Uibutton

I was just experimenting with layer property of my UIButton by setting a outlet n the code for a button created in xib.
NSLog(#"d button layer value%#",dButton.layer.backgroundColor);
But the output is coming as:
d button layer value(null)
My question is: can't we display the layer property value of UIButton. We all know that some default value would have been set for the button.
According to the documentation for CALayer:
The default is nil.
unless you explicitly change it.
In the documentation for UIView, it says this:
The default value is nil, which results in a transparent background color.
This excerpt describes the view.backgroundColor property, so I assume that the view.layer.backgroundColor property is the same.
Hope this helps!
Phew !! I finally got the answer.
Actually I was trying to display the structure value using %# in NSlog statement.
dButton.layer.backgroundColor is a fundamental data type used internally by Quartz to represent colors.
So, way to display them is to make your own class which can parse the value.
Like, for example there are class functions for CGRect, CGPoint etc
like for displaying CGRect we use this code
NSLog(#"d button layer value%#",NSStringFromCGRect(dButton.layer.bounds));
but there arent any function defined for CGColorRef.
Ok, as per jrturton said,for displaying the above value we can use
NSLog(#"d button layer value%#",[UIColor colorWithCGColor:button.layer.backgroundColor)]
I hope everyone got it now !!

maintaining selection in UISegmentedControl

Can i maintain the selected state of UISegmentViewControl segments??
i.e can keep a segment appear selected even if the user selects another segment??
I dont seem to find anything that does this anywhere!!
This isn't possible out of the box. (See How can I enable multiple segments of a UISegmentedControl to be selected?.)
You could try something like this code to provide similar functionality.
I found a way arround this.I placed dark colored image behind each segment and set their hidden property to true.Then i decresed the alpha value of the uisegmented control.Then in the code when a segment is clicked i turn the visibility on or off accordingly,so multiple segments appear selected
Another solution might be using a category:
#import <UIKit/UISegmentedControl.h>
#interface UISegmentedControl (MultiSelect)
#end
Doing this, you have in principle access to private member variables of UISegmentedControl . In particular, you have access to the array holding the button segments, which you can manipulate according to your needs by overriding setSelectedSegmentIndex:selectedSegmentIndex: .However, for various reasons, the attributes declared as private still shouldn't be accessed directly, see this link. As also suggested there, you can rather abuse KVC. So the implementation could look as follows:
#implementation UISegmentedControl (MultiSelect)
- (void)setSelectedSegmentIndex:(NSInteger)selectedSegmentIndex {
NSMutableArray *pArraySegments = [self valueForKey:#"segments"];
if ((pArraySegments) && (selectedSegmentIndex >= 0) && (selectedSegmentIndex < [pArraySegments count])) {
UIButton *pSegment = (UIButton*)[pArraySegments objectAtIndex:selectedSegmentIndex];
pSegment.selected ? (pSegment.selected = NO) : (pSegment.selected = YES);
}
}
#end
This works for me. However, since I now read this discussion, I'm not quite sure if this is really a valid approach.