Dhanesh
Dhanesh

Reputation: 93

Unknown imageview in uiscrollview

I simply added new uiscrollview from interface builder and in viewDidLoad method I am getting its subview and printing it on console. It shows two image views. I can't figure it out where did they come from.

NSArray * views = [friendScrollView subviews];
NSLog(@"views are %@", [views description]); 

In console:

views are (
    "<UIImageView: 0x1b82f0; frame = (805 203; 7 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x1b6cb0>>",
    "<UIImageView: 0x17b1d0; frame = (805 203; 7 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x1bdbd0>>"
)

When I remove them they don't even remove from scroll view. any idea?

Upvotes: 1

Views: 193

Answers (3)

Amar
Amar

Reputation: 13222

These image views are the horizontal and vertical scroll indicator images. They are present by default when you create the UIScrollView instance.

The iOS HIG guidelines for UIScrollView specify

When a scroll view first appears—or when users interact with it—vertical or horizontal scroll indicators flash briefly to show users that there is more content they can reveal.

This is a best practice recommended to be followed to ensure a good user experience. Hence they should not be removed. If at all it is required that the scroll indicators are not to be shown then the scroll view provides properties to achieve this programmatically. Set the required property to NO

  • showsHorizontalScrollIndicator
  • showsVerticalScrollIndicator

Upvotes: 3

Hooda
Hooda

Reputation: 1187

Have you tried the following:

for (UIView *v in friendScrollView.subviews) 
{   
   [v removeFromSuperview];
}

Also use isKindOfClass:[UIImageView class] to only remove imageviews from scrollview in case you have subview of friendScrollView other than imageviews.

Upvotes: 0

Lithu T.V
Lithu T.V

Reputation: 20021

They are the vertical and horizontal scroll indicators and they are not supposed to be removed

UIKIT_CLASS_AVAILABLE(2_0) @interface UIScrollView : UIView <NSCoding> {
    ...
    UIImageView* _verticalScrollIndicator;
    UIImageView* _horizontalScrollIndicator;

Upvotes: 2

Related Questions