I have a UITableView with several sections. In each section are rows with various items. I have a custom UITableViewHeaderFooterView for each section and I would like to set the background image for each one to illustrate a particular percentage associated with each section.
I was thinking I could have a simple image with a line and two colors on either side and somehow scale/translate this image so that the line and bar color would fill up the table header from left to right in accord with the percentage value for that section. This changes so I would need to be able to re-draw it whenever the values change.
I figured that if the image did not scale to fit, but rather the left and right edges were set to bleed instead of tile, then I could just reposition the image in the view. But I'm not quite sure how to go about that, or even if that's a reasonable thing to do. Just looking for advice on a good approach for this sort of effect.
You can add image to the image view and can show the percentage of the image to the image view as per the percentage you get in that particular sections.Fill your image view with full image and display the percentage accordingly.
Instead of using an image, create a custom UIView subclass. Give it a property or two to represent the data. Then implement the drawRect: method to draw the graph.
Use this custom view in the table header/footer view instead of an image.
This has the advantage of being more flexible. If you want the graph to be fancier or different, just update the drawRect: method as needed.
Related
I have a background image for the view controller and two labels. The two labels are not showing up because they are behind the imageview. When I go to editor->arrange the send to front option is not available for the labels. And when I check on the layout debugger I can see the labels are behind the imageview. Is there another way to bring to the labels in front?
Assuming you are using IB, you can move things to the front/back of one another by rearranging them in the left panel. The first item in the list will lie behind every other item. So in this case your list of subviews should go:
1. Image
2. Label
3. Label
This will result in the labels lying one top of the image.
How can I draw a little triangle above the selected item in a UISegmentedControl? Does anyone know an open-source than extends it?
(if not - pointers of how to do it)
Design should look like (this is in the bottom of the screen)
I don't believe there's a native way to do that. You can either find a library that allows for it, but you can do it yourself fairly easily, which I recommend.
I can think of a few out of the box ways to approach it, here at the two I think worth mentioning off the bat:
1) Use UISegmentedControl with images. Make the segmented controller have a height that includes the triangle, and have an image for selected and normal states that shows what you want. The Normal states would have a rectangle of transparency on top, as wide as the entire image and as tall as the triangle. The selected image would include the triangle. Both images should end up the same width and height.
2) Subclass UISegmentedControl and do some custom drawing in drawRect:. You could draw the triangle outside (above) the bounds of the segmented controller, make sure to set the segmented controller's clipToBounds property to NO, as well as its layer's masksToBounds property.
If you'd like more help, or some other suggestions, just ask.
i have spaced out the sections accordingly but the titles i have are centered
but i would like to have it like this
its probably a real simple fix but i dont seem to be able to find it i tried playing with header footer view methods but no go, also the color of it i would like and the outline frame around the section is also what i would like thank you
You are on the right track. You need to implement tableView:viewForHeaderInSection:, not tableView:titleForHeaderInSection:. You can thus return the entire view, colored as you like, and with the label positioned inside it as you like. You must also implement tableView:heightForHeaderInSection: because otherwise the table may try to resize your view in a way you don't want.
An easy way to design the view is to make a view .xib file and design it there. You'll probably want to use a UIView subclass so you can access the label inside it later through an outlet. In tableView:viewForHeaderInSection:, load the nib, pull out the view, configure the label, and return the view.
I have made numerous controls like pickers that had static elements. You could scroll it and pick the number like in standard picker.
But now I need to make a picker that changes its elements based on their position. Here is the image:
I want elements to shift color from white to another color slowly while they are being swiped, and change the size while they are moving. E.G. the central element will be filling with white and getting smaller size and next element should increase in size and fill with other color.
It should also be dynamic, if I go halfway and decide to swipe back, it should work as intended, returning the last central element to its position. So for each pixel I scroll the elements should change.
How do I attack this?
I know the basics, how to call delegate methods, I have this handled, only question is how do I animate this?
I managed to do this with scrollViewDidScroll delegate method, as it gets triggered even if the scroll view was moved 1 pixel.
I set up collection view with cells, and have it send scrollViewDidScroll to each of those cells. Based on the data those cells adjust themselves via CGAffineTransform (for size) and my own written functions that provide relevant color for each offset.
I'm subclassing UIImageView to create sprites, which move around the screen in an app I'm working on. I have a new requirement to add another image to the view, underneath the original view. If I were building this from scratch, I'd composite them as subviews of a common view and use the sendSubviewToBack method for the subview containing the image that needs to go to the back. I'll re-engineer things this way if I have to, but if there's a way to do this in the existing UIImageView, I'd rather do that.
Think of the new image as a shadow or light beam from the original image. They move together, but the original image needs to be on top.
The view will always contain the original image, but it may or may not contain the new image.