I am very perplex as to how Auto Layout and Constrains are handled in iOS 7.
I have a UIView that has an embedded UIScrollView... inside that UIScrollView I have a Container View. Inside this Container View I have 3 Views...
Label
Content Area 1 (10 pt under Label)
Content Area 2 (10 pt under Content Area 2)
Note: these constraints will always the same.
The label will always have the same dimensions.
When the View is first shown on the Screen both Content Area 1 and Content Area 2 are 30 pt in height with an ActivityViewSpinner spinning while 2 separate Ajax calls are made to load the data for these sections.
The data for Content Area 1 will be one of two things... either a 320x320 image or a button asking the user to submit an image.
The data for Content Area 2 will be one of two things... either a label saying there's no data or a UITableView that will be 320x300 full of data).
The use case I'm testing right now is just making the Ajax call for Content Area 1 with an image coming back... I get my Image, however, it doesn't respect the 10pt "top of content area 2 to bottom of content area 1" constraint.
I have implemented updateViewConstraints with the following code
[super updateViewConstraints];
[_containerView addConstraint:[NSLayoutConstraint constraintWithItem:otherSubmissionsView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:mySubmissionView
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:10.0]];
However, here is what the UI looks like:
I am very perplex as to how to go about keeping this constraint in tact.
Any help would be AWESOME.
Related
I have a QScrollArea Widget, which starts empty;
It has a vertical layout, with a QGridLayout, and a vertical spacer to keep it at the top, and prevent it from stretching over the whole scroll area;
Elsewhere in the program, there is a QTextEdit, which when changed, has its contents scanned for "species" elements, and then they are added to the QGridLayout. Any species elements which have been removed are removed too. This bit works;
I have turned the vertical scrollbar on all the time, so that when it appears it does not sit on top of the other stuff in there. Note that the scroll bar is larger than the scroll box already though, despite not needing to be.
This is the problem. The scroll area seems to be preset, and i cannot change it. If i add more rows to the QGridLayout, the scroll area doesn't increase in size.
Instead, it stays the same size, and squeezes the QGridLayout, making it look ugly (at first);
And then after adding even more it becomes unusable;
Note that again, the scroll bar is still the same size as in previous images. The first two images are from Qt Designer, the subsequent 3 are from the program running.
If I resize the window so that the QScrollArea grows, then I see this:
Indicating that there's some layout inside the scroll area that is not resizing properly.
My question is; what do I need to do to make the scrollable area of the widget resize dynamically as I add and remove from the QGridLayout?
If you're coming here from Google and not having luck with the accepted answer, that's because you're missing the other secret invocation: QScrollArea::setWidget. You must create and explicitly identify a single widget which is to be scrolled. It's not enough to just add the item as a child! Adding multiple items directly to the ScrollArea will also not work.
This script demonstrates a simple working example of QScrollArea:
from PySide.QtGui import *
app = QApplication([])
scroll = QScrollArea()
scroll.setWidgetResizable(True) # CRITICAL
inner = QFrame(scroll)
inner.setLayout(QVBoxLayout())
scroll.setWidget(inner) # CRITICAL
for i in range(40):
b = QPushButton(inner)
b.setText(str(i))
inner.layout().addWidget(b)
scroll.show()
app.exec_()
The documentation provide an answer :
widgetResizable : bool
This property holds whether the scroll area should resize the view widget.
If this property is set to false (the default), the scroll area honors the size of its widget.
Set it to true.
Why don't you use a QListView for your rows, it will manage all the issues for you? Just make sure that after you add it you click on the Class (top right window of designer) and assign a layout or it wont expand properly.
I use a QLIstWidget inside a QScrollArea to make a scrollable image list
Try this for adding other objects to the list, this is how I add an image to the list.
QImage& qim = myclass.getQTImage();
QImage iconImage = copyImageToSquareRegion(qim, ui->display_image->palette().color(QWidget::backgroundRole()));
QListWidgetItem* pItem = new QListWidgetItem(QIcon(QPixmap::fromImage(iconImage)), NULL);
pItem->setData(Qt::UserRole, "thumb" + QString::number(ui->ImageThumbList->count())); // probably not necessary for you
QString strTooltip = "a tooltip"
pItem->setToolTip(strTooltip);
ui->ImageThumbList->addItem(pItem);
Update on Artfunkel's answer:
Here's a PySide6 demo that uses a "Populate" button to run the for loop adding items to the scroll area. Each button will also delete itself when clicked.
from PySide6.QtWidgets import *
app = QApplication([])
scroll = QScrollArea()
scroll.setWidgetResizable(True) # CRITICAL
inner = QFrame(scroll)
inner.setLayout(QVBoxLayout())
scroll.setWidget(inner) # CRITICAL
def on_remove_widget(button):
button.deleteLater()
def populate():
for i in range(40):
b = QPushButton(inner)
b.setText(str(i))
b.clicked.connect(b.deleteLater)
inner.layout().addWidget(b)
b = QPushButton(inner)
b.setText("Populate")
b.clicked.connect(populate)
inner.layout().addWidget(b)
scroll.show()
app.exec()
I'm looking for some inspiration. I have some code that is changing the orientation of a page from the default portrait to landscape however the frames I create within the pagetemplates always get created as if they are on a portrait page still.
doc = BaseDocTemplate('test2.pdf', pagesize=landscape(A4))
myFrameThresholdLeft = Frame(
doc.leftMargin,
doc.bottomMargin,
doc.width / 2,
doc.height,
showBoundary=1 # set to 1 for debugging
)
emptyTemplate = PageTemplate(id='emptyTemplate',
pagesize=landscape(A4),
frames=[myFrameThresholdLeft,
myFrameThresholdRight],
onPage=emptyLayout)
elements.append(NextPageTemplate('emptyTemplate'))
elements.append(PageBreak())
I think this is because the values returned by the e.g. doc.width methods are not changing as I change the pagesize in the pagetemplate. Can someone put me on the right tracks here?
How to set a content size of UIScrollView using stroyboard(!) ?
I have a lot of scrollviews, so I don't want to set size of evry one programmaly
You can use IB settings for this.
Click on the UIScrollView you want to set the content size
Go to the identity inspector in the utilities pane on the right of interface builder
Under "User defined runtime attributes
Click on the + button to add a new keyPath
For keyPath column type in contentSize
For type column change it to size
For value column change it to your desired content size value. e.g.: for a width of 320 and height of 600, write { 320, 600 }
Edit:
Here is a screen shot of it in Xcode 5
http://i41.photobucket.com/albums/e282/RobBob3/ScreenShot2014-02-15at94908PM.png
We are developing an application working on both ios6 and ios7
My problem is that, If I check my application in device there is a small white space equal to the size of the status bar at the bottom of the screen.
If I put a dummy status bar at the top of the screen it will make problem in ios6, Help me if you have any solution.
That is the common status bar issue while migrating application from IOS 6 to IOS 7 use this to get ride of the issue:
For more reference
https://stackoverflow.com/a/19025547/1545180
You need to set the delta value for all the controls followed by increasing the origin x to 20pix for all the controls.
Step 1: Increase origin y to 20 pixel (for all the controls in the .xib)
step 2 . And set delta y to - 20 for all the controls in Xib.
Step 3 . Finally change the view as version in interface builder.
If your adding the controls programmatically you need to handle the frames (increase the y position based on the version ) of the added controls like this
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f)
{
[_programmaticallyAddedControl setFrame:CGRectMake(20, 36, 176, 428)];
}
else
{
[_programmaticallyAddedControl setFrame:CGRectMake:CGRectMake(20, 56, 176, 428)];
}
I've created a blur background view which I would like to apply to a particular UIview which contains a number of elements - I would like the new view to be placed behind all other elements.
This is my current code -
[_feedUIView addSubview:blurView ];
All works fine - but it places the new view in front - how can I place it at the back?
Just use this after adding it:
[_feedUIView sendSubviewToBack:blurView]
Do something like this.
[_feedUIView addSubview:blurView];
[_feedUIView sendSubviewToBack:blurView];