wierd shadow under UIView - ios6

I have this simple code:
UIView* shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 30, self.view.frame.size.width, 5)];
shadowView.backgroundColor = [UIColor whiteColor];
shadowView.layer.masksToBounds = NO;
shadowView.layer.shadowOffset = CGSizeMake(0, 0);
shadowView.layer.shadowColor = [[UIColor blackColor] CGColor];
[shadowView.layer setShouldRasterize:YES];
shadowView.layer.shadowOpacity = 1;
[self.view addSubview:shadowView];
This creates a white view with shadow on top and bottom. Both the shadows are oriented nicely, with a gradient from top to bottom.
If I make this change:
shadowView.layer.shadowOffset = CGSizeMake(0, 5);
then the shadow appears only on the bottom (as I wanted) but the gradient is lost somehow. I think the top overlaps the bottom gradient.
How do I make it cast a shadow only on the bottom? (this is under IOS6).
Basically I want to create this image:

Apparently this is just the way shadows work on ios6. The problem was that I was setting a an offset (0, 5) where the 5 was simply larger than the line. After playing with the values for a while, I realized you can cast a shadow downwards, as long as you don't try to get a shadow larger than the image casting the shadow.

Related

WPF - How to work out how much of a canvas background image is cropped?

I have a canvas with a background image:
var bi = new BitmapImage(new Uri(imgLocFull));
var ib = new ImageBrush(bi) {Stretch = Stretch.UniformToFill};
MyCanvas.Background = ib;
I am overlaying various shapes on the image, and want the position of the shapes relative to the background image to be fixed.
If my application window is resized, the amount of the image that is cropped, horizontally and vertically, changes, and when my shapes are redrawn, they do not appear in the same position on the background image.
How can I determine how much of the image has been cropped (to apply an adjustment factor to the overlaid objects' positions?) Or is there a better way of fixing the location of a shape relative to the background image?
Here is my present drawing code:
var l = new Ellipse();
var scb = new SolidColorBrush();
scb.Color = Color.FromRgb(rCol, gCol, bCol);
l.Fill = scb;
l.StrokeThickness = 0;
l.Width = 3;
l.Height = 3;
Canvas.SetBottom(l, point.Y); // * clipping factor here?
Canvas.SetLeft(l, point.X); // * clipping factor here?
MyCanvas.Children.Add(l);
EDIT: Further Clarification
Here's a concrete example of what I am trying to achieve. My image is an aerial photograph, and I want to mark a particular geographical feature (with, say, an ellipse.)
When the window is resized, the ellipse doesn't stay on the feature, it stays relative to the left and top of the canvas.
I can get it closer to the right place by moving it using a factor (newx = newheight/oldheight * oldx) but this doesn't quite work because of the UniformToFill stretch mode, which sees some of the image clipped off the canvas.
The Top and Left of the Canvas are 'anchored', while the Bottom and Right move when resizing... try setting the Canvas.Top Attached Property instead, along with the Canvas.Left Attached Property as you are:
var l = new Ellipse();
var scb = new SolidColorBrush();
scb.Color = Color.FromRgb(rCol, gCol, bCol);
l.Fill = scb;
l.StrokeThickness = 0;
l.Width = 3;
l.Height = 3;
Canvas.SetTop(l, point.Y); // * clipping factor here?
Canvas.SetLeft(l, point.X); // * clipping factor here?
MyCanvas.Children.Add(l);
UPDATE >>>
You asked Or is there a better way of fixing the location of a shape relative to the background image?
I answered this question, so I don't understand why you would need to do anything else... your objects will not move when the screen in resized *if you only set the Grid.Top and Grid.Left properties.

ios : UIScrollView with UITableView

I want to implement one page with vertical scroll view which contains some Images, Labels and one table view in bottom.
Table may have any number of rows. When user scroll to the top other elements such as images, labels should be hide but table should be visible at the top of screen and only table items should be scrolled.
I have tried by setting the currentoffset of scrollview in method scrollViewDidEndDecelerating but its not such smooth.
Scroll view first goes above, comes down and then set the table at top.
Can you please suggest me what should i implement here?
Thanks.
Try this....
// Add image in scrollView
serviceImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"row.png"]];
[serviceImage setBackgroundColor:[UIColor clearColor]];
serviceImage.frame = CGRectMake(10, 10, 300, 100);
[myScrollView addSubview:serviceImage];
[serviceImage release];
// Add label in scrollView
UILabel *rateLbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 105, 300, 20)];
rateLbl.text = #"Rates";
rateLbl.font = [UIFont boldSystemFontOfSize:17.0];
rateLbl.textColor = [UIColor colorWithRed:244/255.0 green:29/255.0 blue:94/255.0 alpha:1.0];
rateLbl.textAlignment = UITextAlignmentLeft;
rateLbl.backgroundColor = [UIColor clearColor];
[myScrollView addSubview:rateLbl];
[rateLbl release];
// Add table in scrollView
int heightRateTbl;
heightRateTbl = [productType count] * 44;
rateTableView.frame =CGRectMake(10, expectedLabelSize.height + expectedDecLblSize.height + heightDayTbl + 555, 300, heightRateTbl);
rateTableView.scrollEnabled = NO;
rateTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[rateTableView reloadData];
You can enable or disable scroll according your choice.
// Set scrollView height
myScrollView.contentSize = CGSizeMake(320, 125 + heightRateTbl);
Do not forget to set delegates and declare all things(in .h file and in .xib file).
Hope i helped.

custom right bar button item in ios6 is not transparent

i am creating a custom right bar button item for my navbar using the following code :
// create a toolbar
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 50, 44.01)];
// create the array to hold the button, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:1];
// create a toolbar item with image
NSString* pathToSettingsResourceFile = [[NSBundle mainBundle] pathForResource:#"19-gear" ofType:#"png"];
UIImage* settingsImage = [[[UIImage alloc] initWithContentsOfFile:pathToSettingsResourceFile] autorelease];
settings = [[UIBarButtonItem alloc]initWithImage:settingsImage style:UIBarButtonItemStylePlain target:self action:#selector(showSettings:)];
settings.enabled = FALSE;
// add button to toolbar
[buttons addObject:settings];
[tools setItems:buttons animated:NO];
[buttons release];
// add toolbar as a right bar button item
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:tools] autorelease];
[tools release];
until ios 6 this works as expected, from ios 6 i am getting this weird rectangle background
and adding
tools.opaque = NO;
tools.backgroundColor = [UIColor clearColor];
doesn't help,
please help me get rid of this background
Thanks in advance,
Amit
I know this is an old thread, but I had the same issue, and thought you might be interested in what I discovered.
A work-around is available in this thread (the answer by jd, not the "accepted" answer).
You should be able to get the behavior you want with this code:
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[tools setBackgroundImage:maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Although this works, I am not convinced that it is the correct way to do it, so I started a new thread here in case anyone knows the secret code for making a UIToolbar containing rectangle behave as a transparent object should.

UISplitViewController Detail View Drop shadow

I'm trying to set a shadow on my UISplitViewController's Detail View, that I want to be visible over the Master View, in iOS 6.
In my Detail ViewController:
self.view.layer.shadowColor = [[UIColor blackColor] CGColor];
self.view.layer.shadowOffset = CGSizeMake(-3.0f, 0.0f);
self.view.layer.shadowRadius = 3.0f;
self.view.layer.shadowOpacity = 1.0f;
self.view.layer.masksToBounds = NO;
self.view.clipsToBounds = NO;
However, the SplitVC automatically clips its sub-views, even when I set it to NO in the above code, and there is no shadow.
Can anyone let me know the correct way to achieve this?
The best way I found to do this is to add a 1px view to the master view controller and snap it to the right edge and apply a shadow to that view instead.
It seems that a superview some way down the hierarchy is performing the clipping.
Try this:
UIView *v = self.view;
do
{
v.clipsToBounds = NO;
v = v.superview;
}
while(v != nil);
Be aware that this will turn of clipping for all view in the hierarchy! - This might be more than you asked for:-).

Windows Phone 7 overflow clipping

I have a grid within a grid and i want the content of the second to move about without encroaching on the first grid.
Much like the panorama view but can move left or right as well as up and down.
I can get this working but unfortunately when you move down the top overflows into the outer grid overlapping any controls within it.
Is there a way to hide the overflow almost like CSS overflow:hidden?
Any help would be really appropriated.
Thank you
Andrew
Possible solution:
var gridWidth = (this.tilesize * (this.gridSize - 1)) / 2;
var top = -(((-offsetY + tileY) * this.tilesize) - gridWidth);
var left = -(((-offsetX + tileX) * this.tilesize) - gridWidth);
this.Container.Margin = new Thickness(left, top, 0, 0);
var clipSection = new RectangleGeometry();
clipSection.Rect = new Rect(-1 * left, -1 * top, 480, 400);
this.Container.Clip = clipSection;
this.Container.Dispatcher.BeginInvoke(new ThreadStart(delegate
{
this.Container.Clip = clipSection;
}));
You could do this by putting something in the cells of the "outer" grid and seeing a higher ZIndex than the elements you are moving around. The elements with the higher ZIndex appear above the lower ones.

Resources